yii2邮箱发送

yii2 邮件发送  163邮箱

1.在配置文件main-local.php components=>[]里面配置

'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,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.163.com', //每种邮箱的host配置不一样
'username' => '18310496083@163.com',
'password' => '774330595a',
'port' => '25',
'encryption' => 'tls',
],

'messageConfig'=>[
'charset'=>'UTF-8',
'from'=>['18310496083@163.com'=>'shanzezhao']
],
],

2.controller控制器中 代码:

<?php $mail= Yii::$app->mailer->compose();

$mail->setTo('***********@qq.com');

$mail->setSubject("邮件测试");

//$mail->setTextBody('zheshisha ');

//发布纯文字文本 $mail->setHtmlBody("<br>问我我我我我");

//发布可以带html标签的文本

if($mail->send()) echo "success"; else echo "failse"; die(); ?>

但愿对您有帮助哦!亲

 

posted @ 2017-03-23 09:23  穷帅哥依然纵横一方  阅读(210)  评论(0编辑  收藏  举报