Yii 1.1: phpmailer

PHPMailer for PHP5/6
17 followers

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!!

Resources

Documentation

Requirements

  • Yii 1.0 or above

Installation

  • Extract the release file under protected/extensions

Usage

See the following code example:

Yii::import('application.extensions.phpmailer.JPhpMailer');
$mail = new JPhpMailer;
$mail->IsSMTP();
$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');
$mail->Send();

Change Log

January 22, 2010

  • Initial release.

Total 12 comments

#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
GoogleMail

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
Confusion

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.

Thanks

public function actionContact()
{
  $model=new ContactForm;
  if(isset($_POST['ContactForm']))
  {
    $model->attributes=$_POST['ContactForm'];
    if($model->validate())
    {
      Yii::import('application.extensions.phpmailer.JPhpMailer'); 
      $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.');
      $this->refresh();
    }
  }
  $this->render('contact',array('model'=>$model));
}
#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->IsSMTP();
$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');
$mail->Send();
#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
Support

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
Great

Works great! Thanx a lot

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

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: +15 / -1
  • Downloaded: 8,495 times
  • Created on: Jan 22, 2010
  • Last updated: Jan 29, 2010