Ad Code



How to send email with attachment in codeigniter

Send Email with attachment

There are a set of configured function for sending mails from codeigniter with attachment of any files, there are the $config array which include the configuration of SMTP mail.

There are use gmail smtp configuration.

function sendMail()
          'mailpath' => '/usr/sbin/sendmail',
          'mailtype'  => 'html', 
          'charset'   => 'iso-8859-1'


        $this->email->from('From Mail', 'From name');
        $this->email->subject('Email Attachment Test');
        $this->email->message('Testing the attachment email class.'); 


            echo "Mail send successfully with attachement!";

There are made some changes like attachment file path:-


If you are use to send mail using html form with file input then use the $_FILES in php and use temp file path for attach in the mail function.

And also other configuration variable:-

From Mail:- this is a mail which is define as a sender mail.
From Name:- sender name.
To(''):- There is a recipient email address.
And Subject and message.

In message section you can also use normal text or html files, if use send html mail then you must use in configuration setting like this:-

'mailtype'  => 'html',

this is define a mail type, and this is also accept normal text and attached files in mail.

Post a Comment


Ad Code