大部分框架都有自带的email邮件发送类,yii的邮件发送也很简单,代码如下:

 修改配置文件,普通版在(config/web.php)。高级版默认配置在/common/config/main-local.php

 'components' => [

    'mailer' => [
  'class' => 'yii\swiftmailer\Mailer',
   'useFileTransport' => false, //false发送邮件,true只是生成邮件在runtime文件夹下,不发邮件
   'transport' => [
  'class' => 'Swift_SmtpTransport',
  'host' => 'smtp.163.com', //每种邮箱的host配置不一样
  'username' => '[email protected]', //发件人邮箱
  'password' => 'xgslagfpomsxuseq', //授权码
  'port' => '25',
   'encryption' => 'tls',
    ],
   'messageConfig'=>[
  'charset'=>'UTF-8',
  'from'=>['[email protected]'=>'nickname'] //发件人昵称
  ],
  ],
  ], 控制器发送邮件(自定义消息) $mail = Yii::$app->mailer->compose();
$mail->setTo('****@qq.com'); //接收人邮箱
$mail->setSubject("test"); //邮件标题
$mail->setHtmlBody("发送内容发送内容发送内容"); //发送内容(可写HTML代码)
if ($mail->send()){
echo "成功";
}else{
echo "失败";
} 如果发送页面 $mail = Yii::$app->mailer->compose("email"); //在mail文件夹下创建email页面文件,在文件内编辑内容
$mail->setTo('****@qq.com'); //接收人邮箱
$mail->setSubject("test"); //邮件标题
if ($mail->send()){
echo "成功";
}else{
echo "失败";
}
04-28 14:23