- 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
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.
$this->load->library('email');
Send Text Email:
Here is an example code to send text email in CodeIgniter.$this->email->to('recipient@example.com');$this->email->from('codexworld@gmail.com','CodexWorld');$this->email->subject('Test Email (TEXT)');$this->email->message('Text email testing by CodeIgniter Email library.');$this->email->send();
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 initialize
function. Here is an example code to send HTML email in CodeIgniter.$htmlContent = '<h1>HTML email testing by CodeIgniter Email Library</h1>';$htmlContent .= '<p>You can use any HTML tags and content in this email.</p>'; $config['mailtype'] = 'html';$this->email->initialize($config);$this->email->to('recipient@gmail.com');$this->email->from('codexworld@gmail.com','CodexWorld');$this->email->subject('Test Email (HTML)');$this->email->message($htmlContent);$this->email->send();
Send Email with Attachment:
Useattach()
function of Email class to attach files in email. Here is an example code to send an email with attachment in CodeIgniter.$htmlContent = '<h1>HTML email with attachment testing by CodeIgniter Email Library</h1>';$htmlContent .= '<p>You can attach the files in this email.</p>'; $config['mailtype'] = 'html';$this->email->initialize($config);$this->email->to('recipient@gmail.com');$this->email->from('codexworld@gmail.com','CodexWorld');$this->email->subject('Test Email (Attachment)');$this->email->message($htmlContent);$this->email->attach('files/attachment.pdf');$this->email->send();
Send Email to Multiple Recipient(s):
Usingto()
function of Email class, you can send email
to single or multiple recipient(s). Provide single email,
comma-delimited list or an array.$this->email->to('one@example.com');OR
$this->email->to('one@example.com, two@example.com, three@example.com');OR
$recipientArr = array('one@example.com', 'two@example.com', 'three@example.com');$this->email->to($recipientArr);
Sets the CC and BCC Email Address(s):
Just liketo()
, you can provide single email, comma-delimited list or an array in cc()
and bcc()
.$this->email->cc('another@example.com');
$this->email->bcc('another@example.com');
0 comments:
Post a Comment