Yii 1.1: phpmailer

PHPMailer for PHP5/6

PHP email transport class featuring file attachments, SMTP servers, CCs, BCCs, HTML messages, word wrap, and more. Sends email via sendmail, PHP mail(), QMail, or with SMTP. New PHPMailer for PHP5 released!!




  • Yii 1.0 or above


  • Extract the release file under protected/extensions


See the following code example:

$mail = new JPhpMailer;
$mail->Host = 'smpt.163.com';
$mail->SMTPAuth = true;
$mail->Username = 'yourname@163.com';
$mail->Password = 'yourpassword';
$mail->SetFrom('yourname@163.com', 'yourname');
$mail->Subject = 'PHPMailer Test Subject via smtp, basic with authentication';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
$mail->MsgHTML('<h1>JUST A TEST!</h1>');
$mail->AddAddress('john.doe@otherdomain.com', 'John Doe');

Change Log

January 22, 2010

  • Initial release.

Total 14 comments

#19163 report it
bighoc at 2015/04/01 07:59am
Doesn't work in console mode.

Have any idea why ? In web version everything is fine, but in console mode is not. When I try to use $mailer->Send() it start thinking about a minute, after that script dies. It doesn't show me any errors or something else.

Thing is that the same code sends mail in web mode, but doesn't in console.(all params are the same at console and at web apps).

Here is my code:

$email = Yii::app()->mailer;
$email->ContentType = 'text/html';
$email->From = Yii::app()->params['noReplyEmail'];
$email->FromName = Yii::app()->params['noReplyTitle'];
$email->Subject = 'my subject';
$email->Body = 'Hello!';
#18324 report it
BornToDrink at 2014/10/15 11:07am

Working great. Thank you for the extension.

#15743 report it
noorr_swati at 2013/12/11 07:54am
Smtp Error: Could Not Connect To Smtp Host

i am getting the error => Smtp Error: Could Not Connect To Smtp Host

can any one tell how to fix it thnx... :)

#9607 report it
daniel.fiechter at 2012/08/28 02:14pm

Not sure if it already works for you, but if you want to connect to a google mail account you have to set up the host like this:

$mail->Host = 'smtp.googlemail.com:465';
$mail->SMTPSecure = "ssl";
#9160 report it
rude at 2012/07/24 07:35pm
Thank you!

Thank you for adding this as an extension. Works fantastic after tons of trouble with two other mailers.

Thanks again.

#8812 report it
ilovebutternut at 2012/06/29 08:01am

Thanks for the simple extension.

I had a bit of problem with the Gmail SMTP connection, but eventually found that adding the following solved the problem.

$mail->SMTPSecure = "ssl";

When I click submit on the default contact page form, the flash message tells my the email has been sent. This happens on localhost and the live test server. I am not sure why the code is executing correctly but no emails are arriving. (And yes, the email addresses and passwords were all correct and valid :)

I have the following code in my controller, please take a look and tell me if I'm missing something.


public function actionContact()
  $model=new ContactForm;
      $mail = new JPhpMailer; $mail->IsSMTP(); 
      $mail->SMTPSecure = "ssl";  
      $mail->Host = 'smtp.gmail.com'; 
      $mail->SMTPAuth = true; 
      $mail->SMTPSecure = true; 
      $mail->Username = 'myusername@gmail.com'; 
      $mail->Port = '465'; 
      $mail->Password = '******'; 
      $mail->SMTPKeepAlive = true;  
      $mail->Mailer = "smtp"; 
      $mail->IsSMTP(); // telling the class to use SMTP  
      $mail->SMTPAuth   = true;  
      $mail->CharSet = 'utf-8';  
      $mail->SMTPDebug  = 0;
      $mail->SetFrom('myusername@gmail.com', 'myname'); 
      $mail->Subject = 'PHPMailer Test Subject via GMail, basic with authentication'; 
      $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; 
      $mail->MsgHTML('<h1>JUST A TEST!</h1>'); 
      $mail->AddAddress('to@someone.co.za', 'John Doe'); $mail->Send();
      Yii::app()->user->setFlash('contact','Thank you for... as possible.');
#5635 report it
falcon at 2011/10/27 03:25am
Gmail Testing fail

I am using Gmail also, but I fail to send email. Below is the snippet

$mail = new JPhpMailer;
$mail->Host = 'smtp.gmail.com';
$mail->Port = '465';
$mail->SMTPSecure = 'SSL';
$mail->SMTPAuth = true;
$mail->Username = 'mygmail@gmail.com';
$mail->Password = 'password';
$mail->SetFrom('mygmail@gmail.com', 'Falcon');
$mail->Subject = 'Welcome to Hazel Eyes';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
$mail->MsgHTML('<h1>JUST A TEST!</h1>');
$mail->AddAddress('myother@hotmail.com', 'Falcon CK');
#3836 report it
jerry2801 at 2011/05/13 12:35am
reply to prchakal

renderPartial() in your controller is simple~

#3833 report it
prchakal at 2011/05/12 10:06pm

VIEW / THEME supports?

#2657 report it
el chief at 2011/01/25 10:21pm
How is this better than just using the raw php file?

I can put phpmailer.php in my components folder and call $mail = new phpmailer();

why bother with the extension?

#234 report it
tsbtjy at 2010/07/30 05:35am
good email

It works good!

but if use it as components you must edit it.

such as:

add init();

add reply-to email;

change the iso-8859-1 to utf-8 for subject is not show in chinese.

#243 report it
Sart at 2010/07/28 07:31pm
Only ....

Suppose smtp require SSL auth, such smtp as smtm.gmail.com ?

What than ?

#556 report it
someone at 2010/04/27 08:57am

Works great! Thanx a lot

#610 report it
luis diego at 2010/04/08 01:20pm

It works for me. Thank you for the extension.

Leave a comment

Please to leave your comment.

Create extension
  • Yii Version: 1.1
  • License: New BSD License
  • Developed by: jerry2801
  • Category: Mail
  • Votes: +19 / -1
  • Downloaded: 10,215 times
  • Created on: Jan 22, 2010
  • Last updated: Jan 29, 2010