Archive

Posts Tagged ‘phpmailer’

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) .

download:

phpmailer for codeigniter

usage:

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()
	{
		parent::Controller();
	}

   function testMailer()
   {
	   error_reporting(E_ERROR);

	   $this->load->plugin('phpmailer');
	   $mail=new PHPMailer();

	/*$mail->IsSMTP();
	$mail->SMTPAuth   = true;                  // enable SMTP authentication
	$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
	$mail->Host       = "smtp.gmail.com";      // 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
	//print_r($mail);
	$mail->WordWrap   = 50; // set word wrap

	$mail->AddAddress("[email protected]");
	$mail->AddReplyTo("[email protected]","sender name");
	$mail->AddAttachment("/path/to/file.zip");             // 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";
	}

   }
}

?>
50 queries in 0.109 seconds