How to Send Gmail using CodeIgniter Email Library

Share on TwitterDigg This

send mail using SMTP in codeigniter php using email library

// Set SMTP Configuration
$emailConfig = array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'yourgoogleaccount@googlemail.com',
    'smtp_pass' => 'yourgooglepassowrd',
);
// Set your email information
$from = array('email' => 'yourgoogleaccount@gmail.com',
            'name' => 'Your Name');
$to = array('recipient_address@gmail.com',
           'other@email.com');
$subject = 'Your gmail subject here';
$message = 'Type your gmail message here';
// Load CodeIgniter Email library
$this->load->library('email', $emailConfig);
// Sometimes you have to set the new line character for better result
$this->email->set_newline("\r\n");
// Set email preferences
$this->email->from($from['email'], 
$from['name']);$this->email->to($to);
$this->email->subject($subject);
$this->email->message($message);
// Ready to send email and check whether the email was successfully sent
if (!$this->email->send()) {
    // Raise error message
    show_error($this->email->print_debugger());
}
else {
    // Show success notification or other things here
    echo 'Success to send email';
}

Random

About prabin t p

Connect with me on Google+
This entry was posted in codeigniter, php. Bookmark the permalink.

One Response to How to Send Gmail using CodeIgniter Email Library

  1. I cherished as much as you will receive performed proper here. The caricature is tasteful, your authored material stylish. nonetheless, you command get got an nervousness over that you would like be handing over the following. unwell no doubt come more formerly once more as exactly the similar nearly a lot often within case you shield this hike.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">