Posts Tagged ‘Programming’

phpmailer for codeigniter (ci)

May 19th, 2008 15 comments

on our new server we was getting problem with mail sending. yahoo and some other mail server was not receiving our mails to there inbox. so i imported the most popular php class (phpmailer ) in codeigniter as plugin. it’s install and use is too simple. you have to download the zip file from here, then unzip it to your plugin (systemplugins) folder. then edit phpmailer_pi.php , and edit the default configuration as needed as your mail server (default configuration will work fine with gmail smtp, you only have to edit the user name and pass) .


phpmailer for codeigniter


you can now use all the functions that phpmailer supported. here is a the example that you will get in phpmailer site, but in ci format.

 < ?php
 * Created on May 19, 2008
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 class Action extends Controller {
	function Action()
   function testMailer()
	   $mail=new PHPMailer();
	$mail->SMTPAuth   = true;                  // enable SMTP authentication
	$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
	$mail->Host       = "";      // sets GMAIL as the SMTP server
	$mail->Port       = 465;                   // set the SMTP port 
	$mail->Username   = "[email protected]";  // GMAIL username
	$mail->Password   = "xxxxxx";            // GMAIL password
	$mail->From       = "[email protected]";
	$mail->FromName   = "sender name";
	$mail->Subject    = "This is the subject";
	$mail->Body       = "Hi,This is the HTML BODY";                      //HTML Body
	$mail->AltBody    = "This is the body when user views in plain text format"; //Text Body
	$mail->WordWrap   = 50; // set word wrap
	$mail->AddAddress("[email protected]");
	$mail->AddReplyTo("[email protected]","sender name");
	$mail->AddAttachment("/path/to/");             // attachment
	$mail->AddAttachment("/path/to/image.jpg", "new.jpg"); // attachment
	$mail->IsHTML(true); // send as HTML
	if(!$mail->Send()) {
	  echo "Mailer Error: " . $mail->ErrorInfo;
	} else {
	  echo "Message has been sent";
Views :24236
43 queries in 0.556 seconds