
The first thing we do download PHPMailer library then move it to /system/application/libraries or /application/libraries/
my_phpmailer.php
1 2 3 4 5 6 7 8 9 | //my_phpmailer.php <?php if ( ! defined( 'BASEPATH' )) exit ( 'No direct script access allowed' ); class My_PHPMailer { public function My_PHPMailer() { require_once( 'PHPMailer/class.phpmailer.php' ); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <?php class My_Controller extends Controller { public function My_Controller(){ parent::Controller(); $ this ->load->library( 'My_PHPMailer' ); } public function send_mail() { $mail = new PHPMailer(); $mail->IsSMTP(); // we are going to use SMTP $mail->SMTPAuth = true ; // enabled SMTP authentication $mail->SMTPSecure = "ssl" ; // prefix for secure protocol to connect to the server $mail->Host = "smtp.gmail.com" ; // setting GMail as our SMTP server $mail->Port = 465; // SMTP port to connect to GMail $mail->Username = "myusername@gmail.com" ; // user email address $mail->Password = "password" ; // password in GMail $mail->SetFrom( 'info@yourdomain.com' , 'Firstname Lastname' ); //Who is sending the email $mail->AddReplyTo( "response@yourdomain.com" , "Firstname Lastname" ); //email address that receives the response $mail->Subject = "Email subject" ; $mail->Body = "HTML message "; $mail->AltBody = "Plain text message" ; $destino = "addressee@example.com" ; // Who is addressed the email to $mail->AddAddress($destino, "Ednalan" ); $mail->AddAttachment( "images/phpmailer.gif" ); // some attached files $mail->AddAttachment( "images/phpmailer_mini.gif" ); // as many as you want if (!$mail->Send()) { $data[ "message" ] = "Error: " . $mail->ErrorInfo; } else { $data[ "message" ] = "Message sent correctly!" ; } $ this ->load->view( 'sent_mail' ,$data); } } |