yii 使用 phpmailer发送邮件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了yii 使用 phpmailer发送邮件相关的知识,希望对你有一定的参考价值。

原文链接 :  http://www.yiiframework.com/extension/mailer/

下载插件放在 :XXX/protected/extensions/

 

作为一个普通的组建使用 :

<?php
$message = ‘Hello World!‘;
$mailer = Yii::createComponent(‘application.extensions.mailer.EMailer‘);
$mailer->Host = ‘smtp.163.com‘;
$mailer->SMTPAuth = true;
$mailer->IsSMTP(); $mailer->From = ‘[email protected]; $mailer->AddReplyTo(‘[email protected]); $mailer->AddAddress(‘[email protected]);
$mailer->Username = ‘[email protected]‘;
$mailer->Password = ‘XXXXX‘;
$mailer->FromName = ‘XXX‘; $mailer->CharSet = ‘UTF-8‘; $mailer->Subject = Yii::t(‘demo‘, ‘Yii rulez!‘); $mailer->Body = $message; $mailer->Send();

 

作为一个应用组建使用 :

在yii的config/main 里面 增加一下代码 

<?php
‘components‘=>array(
   ‘mailer‘ => array(
      ‘class‘ => ‘application.extensions.mailer.EMailer‘,
      ‘pathViews‘ => ‘application.views.email‘,
      ‘pathLayouts‘ => ‘application.views.email.layouts‘
   ),
   // ...
}

然后在controller:

<?php
$message = ‘Hello World!‘;
Yii::app()->mailer->Host = ‘smtp.163.com‘;
Yii::app()->mailer->SMTPAuth = true; Yii
::app()->mailer->IsSMTP(); Yii::app()->mailer->From = ‘[email protected]; Yii::app()->mailer->FromName = ‘XXX‘;
Yii::app()->mailer->Username = ‘[email protected]‘;
Yii::app()->mailer->Password = ‘XXX‘; Yii
::app()->mailer->AddReplyTo(‘[email protected]); Yii::app()->mailer->AddAddress(‘[email protected]); Yii::app()->mailer->Subject = ‘Yii rulez!‘;
Yii::app()->mailer->CharSet = ‘UTF-8‘; Yii
::app()->mailer->Body = $message; Yii::app()->mailer->Send();

 

PS:QQ发送邮件比较麻烦,不作演示

以上是关于yii 使用 phpmailer发送邮件的主要内容,如果未能解决你的问题,请参考以下文章

使用 html 代码发送 phpmailer 电子邮件

使用 DKIM 密钥在 phpmailer 中发送邮件

thinkphp中怎么使用phpmailer发送邮件

PHP 通过PHPMailer发送邮件

PHP 通过PHPMailer发送邮件

使用 PHPMailer 发送邮件