关于thinkphp3.2.3集成phpmailer

关于thinkphp3.2.3集成phpmailer

 

1 我用的是phpmailer5.1的版本  先把文件解压缩放到这个位置

关于thinkphp3.2.3集成phpmailer

 

2 封装到函数里面

function email($email,$title,$content)
{
    //邮件发送服务器
    $emailHost='smtp.163.com';
    //邮件发送端口
    $emailPort='25';
    
    //邮件发送超时时间
    $emailTimeout='20';
    //发件人邮箱
    $emailUserName='这里面写邮箱正好';
    //发件人邮箱密码
    $emailPassword='如果是163的这里写客户端授权码';
    //发件人姓名
    $emailFormName='abc';
    //收件人邮箱
    $toemail=$email;
    //邮件标题
    $subject=$title;
    //邮件内容
    $message=$content;

    vendor('phpmailer.class#phpmailer'); //从PHPMailer目录导class.phpmailer.php类文件  //注意这个比较重要
    vendor('SMTP');
    $mailer=new phpmailer();

    //邮件配置
    $mailer->SetLanguage('zh_cn');
    $mailer->Host = $emailHost;
    //$mailer->Port = $emailPort;
    $mailer->SMTPSecure = 'ssl';
    $mailer->Port = 465;
    $mailer->Timeout = $emailTimeout;
    $mailer->ContentType = 'text/html';//设置html格式
    $mailer->SMTPAuth = true;
    $mailer->Username = $emailUserName;
    $mailer->Password = $emailPassword;
    $mailer->IsSMTP();
    $mailer->From = $mailer->Username; // 发件人邮箱
    $mailer->FromName =$emailFormName;
    $mailer->AddReplyTo( $mailer->Username );
    $mailer->CharSet = 'UTF-8';

    // 发送邮件
    $mailer->AddAddress( $toemail );
    $mailer->Subject = $subject;
    $mailer->Body = $message;
    if ($mailer->Send() === true) {
        return true;
    } else {
        $error = $mailer->ErrorInfo;
        return false;
    }
}

 

3  然后在控制器里面写个调用此函数

 public function testmail()
 {
     
     $email='收件人的邮箱地址';
     $title='测试的标题';
     $content='测试的内容,支持html格式';
     email($email,$title,$content);
 }

 

上一篇:phpMailer中的附件


下一篇:如果PHPMailer失败,则回退到本机PHP邮件功能