Example – Sending Email in CodeIgniter Framework

0 70

Sending email in CodeIgniter is much easier and you can set preferences as per your needs. CodeIgniter provides an Email library to sending email in application. CodeIgniter’s Email class provides the following features.

  • Multiple Protocols: Mail, Sendmail, and SMTP
  • Multiple recipients
  • CC and BCCs
  • HTML or Plaintext email
  • Attachments
  • Word wrapping
  • Priorities
  • BCC Batch Mode, enabling large email lists to be broken into small BCC batches.
  • Email Debugging tools

In this tutorial, we’ll show the mostly used email features for the web project. Using our sample code you can send a text email, HTML email, and email with an attachment. Also, you would be able to set the cc email address(s) and bcc email address(s).

To send an email in CodeIgniter, you have to load the email library first. Use the following line of code to load the CodeIgniter’s Email library.

Send Text Email:

Here is an example code to send text email in CodeIgniter.

Send HTML Email:

To send an email with HTML content, set a preference (mailtype) by passing an array of preference value (html) to the email initializefunction. Here is an example code to send HTML email in CodeIgniter.

Send Email with Attachment:

Use attach() function of Email class to attach files in email. Here is an example code to send an email with attachment in CodeIgniter.

Send Email to Multiple Recipient(s):

Using to() function of Email class, you can send email to single or multiple recipient(s). Provide single email, comma-delimited list or an array.

OR

OR

Sets the CC and BCC Email Address(s):

Just like to(), you can provide single email, comma-delimited list or an array in cc() and bcc().

 

You might also like More from author

Leave A Reply

Your email address will not be published.