当前位置: 移动技术网 > IT编程>开发语言>PHP > PHP实现全自动化邮件发送 phpmailer

PHP实现全自动化邮件发送 phpmailer

2019年02月01日  | 移动技术网IT编程  | 我要评论

phpmailer           composer地址

function sendmail($msg,$theme,$content)
    {
        $mail = new \phpmailer\phpmailer\phpmailer(); //传递true参数,表示使用异常机制
        /*基本设置*/
        $mail->issmtp();                                      // 设置使用smtb服务
        $mail->host = config('email_163.host');  // 设置邮箱服务器地址
        $mail->smtpauth = true;                               // 开启stmp认真
        $mail->username = config('email_163.username');  // 邮箱账号
        $mail->password = config('email_163.appkey');  // 邮箱key
        $mail->smtpsecure = 'tls';                            // 安全加密方式 tls ssl
        $mail->port = 25;                                    // 邮箱发送端口号 邮箱默认是25
        $mail->charset= 'utf-8';                             //编码格式
        /*收件发件人信息*/
        $mail->setfrom(config('email_163.username'));  //发件人账号
        $mail->addaddress($msg);                            // 收件人信息
        /*主题内容*/
        $mail->ishtml(true); //设置邮件内容格式 为html
        $mail->subject = $theme;  //主题
        $mail->body = $content;   //邮件内容
        $res = $mail->send();
        if ($res)
        {
            return true;
        }else{
            return $mail->errorinfo;
        }
    }

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网