Yii框架利用PHPMailer发送邮件

2017-01-10 · 🙈Lei · 0条 · 426次

Yii框架basic版本

1.配置(web.php)

'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => false, //需要设置成false
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.163.com', //每种邮箱的host配置不一样,需要到自己邮箱开通权限
'username' => 'nuoone@163.com', //自己的邮箱
'password' => '***', //开通邮箱smtp时设置的密码
'port' => '25', //端口
'encryption' => 'tls',
],
'messageConfig'=>[
'charset'=>'UTF-8'
],
],

2.使用方法

 * @param [type] $toEmail 将邮件发送给谁 
 * @param [type] $fromEmail 发送人邮箱
 * @param [type] $name 发送人昵称
 * @param [type] $title 邮件主题
 * @param [type] $content 邮件内容 $mail = Yii::$app->mailer->compose()
->setTo($toEmail)
->setFrom([$fromEmail=>$name])
->setSubject($title)
->setHtmlBody($content)
->send();


  0