yii 邮件发送

邮件都能做什么
1.邮件找回密码
2.邮件激活账号
3.邮件发送验证码
4.公司的邮件服务器,可以作为项目管理系统

5.邮件推送链接 促销,新品 等信息

6.推送一些提醒消息

了解一个概念

邮件营销

在yii2中 操作phpmailer
首先是加载我们邮箱的组件

‘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.qq.com’,
‘username’ => ‘***’,
‘password’ => ‘**’,
‘port’ => ’25’,
‘encryption’ => ‘tls’,

],
‘messageConfig’=>[
‘charset’=>’UTF-8’,
‘from’=>[‘***’=>’admin’]
],
]

public function actionSendmail(){
//加载配置的组件
$mail = Yii::$app->mailer->compose();
//要发给谁
$mail->setTo(‘1054762539@qq.com’);
//标题 主题
$mail->setSubject(“test”);
//内容
$mail->setHtmlBody(“我我我我”);
if ($mail->send())
echo “成功”;
else
echo “失败”;
die();

posted @ 2018-08-09 14:13  木楊  阅读(166)  评论(0编辑  收藏  举报