Home  >  Article  >  Backend Development  >  Use PHPMailer with QQ mailbox to send emails

Use PHPMailer with QQ mailbox to send emails

不言
不言Original
2018-04-24 10:14:001512browse

The content of this article is about using PHPMailer to send emails with QQ mailbox. It has certain reference value. Now I share it with everyone. Friends in need can refer to it

// 开启php_openssl以及php_sockets
<?php/**
 * Created by PhpStorm.
 * Date: 2018/4/23
 * Time: 23:14
 */namespace app\common\sendingpay;use \think\Controller;use app\common\phpmailer\PHPMailer;/**
 * 发送邮件确认支付
 *
 */class SendingPay extends Controller{

    function __construct()
    {
        parent::__construct();
    }    public function trigger($totalAmount, $ordernum)
    {
        $body = &#39;订单支金额&#39;.$totalAmount.&#39;,订单ID(ordernum)&#39;.$ordernum;        $this->sendmail(&#39;j.@foxmail.com&#39;, $body);
    }    public function sendmail($toemail = &#39;&#39;, $body = &#39;&#39;)
    {
        // 开启php_openssl以及php_sockets
        $sendmail = &#39;j.c@foxmail.com&#39;; //发件人邮箱
        $sendmailpswd = "jvqdkdyhswg"; //客户端授权密码,而不是邮箱的登录密码!
        $send_name = &#39;LXX&#39;;// 设置发件人信息,如邮件格式说明中的发件人,
        $toemail = &#39;j.c@foxmail.com&#39;;//定义收件人的邮箱
        $to_name = &#39;LXXback&#39;;//设置收件人信息,如邮件格式说明中的收件人
        $mail = new PHPMailer();        $mail->SMTPDebug = 1;        $mail->isSMTP();// 使用SMTP服务
        $mail->CharSet = "utf8";// 编码格式为utf8,不设置编码的话,中文会出现乱码
        $mail->Host = "smtp.qq.com";// 发送方的SMTP服务器地址
        $mail->SMTPAuth = true;// 是否使用身份验证
        $mail->Username = $sendmail;//// 发送方的
        $mail->Password = $sendmailpswd;//客户端授权密码,而不是邮箱的登录密码!
        $mail->SMTPSecure = "ssl";// 使用ssl协议方式
        $mail->Port = 465;//  qq端口465或587)
        $mail->isHTML(true);        $mail->setFrom($sendmail, $send_name);// 设置发件人信息,如邮件格式说明中的发件人,
        $mail->addAddress($toemail, $to_name);// 设置收件人信息,如邮件格式说明中的收件人,
        $mail->addReplyTo($sendmail, $send_name);// 设置回复人信息,指的是收件人收到邮件后,如果要回复,回复邮件将发送到的邮箱地址
        //$mail->addCC("xxx@qq.com");// 设置邮件抄送人,可以只写地址,上述的设置也可以只写地址(这个人也能收到邮件)
        //$mail->addBCC("xxx@qq.com");// 设置秘密抄送人(这个人也能收到邮件)
        //$mail->addAttachment("bug0.jpg");// 添加附件
        $mail->Subject = "订单支付确认";// 邮件标题
        $mail->Body = $body;// 邮件正文
        //$mail->AltBody = "This is the plain text纯文本";// 这个是设置纯文本方式显示的正文内容,如果不支持Html方式,就会用到这个,基本无用

        if (!$mail->send()) {// 发送邮件
            //echo "Mailer Error: ".$mail->ErrorInfo;// 输出错误信息
            return -1;
        } else {            return 1;
        }
    }
}


Downloaded source file namespacenamespace app\common\phpmailer;

Related recommendations:

<a href="http://www.php.cn/php-weizijiaocheng-393266.html" target="_self">PHPMAILER implementation PHP email function</a>

PHP uses PHPMailer to send email method sharing

The above is the detailed content of Use PHPMailer with QQ mailbox to send emails. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn