Warning: fopen(https://www.tutorialsplane.com/'. $cid .'): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in /home/u613989013/domains/tutorialsplane.com/public_html/wp-content/plugins/amp/includes/lib/class-fastimage.php on line 31
Codeigniter Email Library - Send Email | Attachments | Image
Tutorialsplane

Codeigniter Email Library


Codeigniter Email Library: Codeigniter provides email library to send emails. It is very easy to use this library and send emails. You can configure it on the fly. Here in this tutorial we are going to demonstrate how to use email library in codeigniter and send mails.


Codeigniter Email Library | Send Mail Example

First of all we need to load the mail library before using it. We can load library simply as below-

Syntax

Codeigniter Load Email Library Syntax

$this->load->library('email');

Now you can use it to send mails.

Example

Let us create a simple example to send email-

Codeigniter Send Email Example

$this->load->library('email');
$this->email->from('sender@example.com', 'Your Name');
$this->email->to('receiver@example.com');
$this->email->cc('ccmail@example.com');
$this->email->bcc('bcc@example.com');
$this->email->subject('Codeigniter Email Test');
$this->email->message('This is test mail.');
$this->email->send();

Learn More

Let us have look over more examples.


Send Attachments

You can also attach some file in email using the following method –

Codeigniter Send Email Example

$this->load->library('email');
$this->email->from('sender@example.com', 'Your Name');
$this->email->to('receiver@example.com');
$this->email->cc('ccmail@example.com');
$this->email->bcc('bcc@example.com');
$this->email->subject('Codeigniter Email Test');
$this->email->message('This is test mail.');
$this->email->attach('http://example.com/myfile.pdf');
// or just give file path $this->email->attach('path/myfile.pdf');
$this->email->send();

Send Inline Attachments

If you want to send inline attachments you can use $this->email->attachment_cid() to send inline attachments-

Codeigniter Send Inline(image) Attachments

$this->load->library('email');
$this->email->from('sender@example.com', 'Your Name');
$this->email->to('receiver@example.com');
$this->email->cc('ccmail@example.com');
$this->email->bcc('bcc@example.com');
$this->email->subject('Codeigniter Email Test');
$this->email->message('This is test mail.');
$filename = "images/profile.png";
$cid = $this->email->attachment_cid($filename);
$this->email->message('<amp-img src="cid:'. $cid .'" alt="Image Attachments" width="600" height="400" class="amp-wp-unknown-size amp-wp-enforced-sizes" sizes="(min-width: 600px) 600px, 100vw"></amp-img>');
$this->email->send();