webhost

Web hosting

Wednesday, February 15, 2012

How to Send Gmail using CodeIgniter 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 sentif (!$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';
}
 

No comments:

Post a Comment