tp3.2整合phpmailer邮件发送

浏览:1549 发布日期:2018/04/29 分类:功能实现 关键字: 邮件发送 QQ邮件 tp3.2
邮件发送 QQ 简单
我这里用的代理是qq邮箱,首先开启邮箱SMTP服务:打开qq邮箱左上角设置-> 账户-> POP3/SMTP服务 点击开启发个短信即可 验证完会有一串字符串 保留后面需要。
接下来下载 phpmailer https://pan.baidu.com/s/1J8hL48HI4BCcpD3UqDtROg 密码:43m1
将下载好的文件放到Thinkphp/ThinkPHP/Library/Vendor/下。
在对应的控制器中   private function sendMail($one,$two,$three,$title,$content)
  {

        require('./ThinkPHP/Library/Vendor/phpmailer/class.phpmailer.php');

        try {

            $mail = new \PHPMailer(true);

            $mail->IsSMTP();

            $mail->SMTPSecure = 'ssl';

            $mail->CharSet = 'UTF-8';

            $mail->SMTPAuth = true; //开启认证

            $mail->Port = 465;    //网易为25

            $mail->Host = "smtp.qq.com";

            $mail->Username = "你的qq号";    //qq此处为邮箱前缀名

            $mail->Password = "类似密码"; //开启qq邮箱SMTP服务时获得

            $mail->AddReplyTo("你的qq号@qq.com", "first");//回复地址

            $mail->From = "你的qq号@qq.com";

            $mail->FromName = '你的qq号';

            $mail->AddAddress($one);
            $mail->AddAddress($two);
            $mail->AddAddress($three);

            $mail->Subject = $title;

            $mail->Body = $content;

            $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; //当邮件不支持html时备用显示

            $mail->WordWrap = 80; // 设置每行字符串的长度

//$mail->AddAttachment("f:/test.png"); //可以添加附件

            $mail->IsHTML(true);

            $mail->Send();

            echo '发送成功';

        } catch (phpmailerException $e) {

            $e->errorMessage();

        }

    }
在想要使用发送邮件的方法中调用即可    public function test()
    {

        $one = 'xxxxxx@qq.com';

        $two = 'xxxxx@qq.com';

        $three = 'xxxxx@163.com';

        $title = 'test';

        $content = 'this is test data';

        $this -> sendMail($one,$two,$three,$title,$content);
    }
注意:1、我这里是发送三个不同邮箱根据自己需求调整 2、如果在不同的控制器中调用,可将sendMail() 方法放到common/function.php 中
评论( 相关
后面还有条评论,点击查看>>