zoukankan      html  css  js  c++  java
  • 发送信息到邮箱的第三方扩展库PHPMailer使用方法

    一.下载

    使用composer下载PHPMailer :composer require phpmailer/phpmailer

    二.使用实例

    use PHPMailerPHPMailerPHPMailer;
    use PHPMailerPHPMailerSMTP;
    use PHPMailerPHPMailerException;
    function mailto($to, $title, $content)
    {
        $mail = new PHPMailer(true); // 开发环境写成true 显示异常 生产环境改为false
     // QQ邮箱
        try {
            //Server settings 服务器配置
            $mail->SMTPDebug = 0;                                                         //  0 表示关闭异常提示 2开启调试模式
            $mail->CharSet = 'utf-8';                 // 字符编码
            $mail->isSMTP();                                                                     // 使用SMTP,只接收信息
            $mail->Host       = 'smtp.qq.com';                                            // SMTP服务器地址
            $mail->SMTPAuth   = true;                                                      // 启用SMTP身份验证
            $mail->Username   = '327*****780@qq.com';                        // SMTP username
            $mail->Password   = 'zqa*****yypchag';                              // SMTP password 开启SMTP授权码
            $mail->SMTPSecure = 'ssl';                                                     // 使用ssl加密
            $mail->Port       = 465;                                                             // 端口

            //Recipients  接受信息
            $mail->setFrom('327*****780@qq.com', '*****企业');               // 发送方邮箱
            $mail->addAddress($to);                                                           // 接受方邮箱

            // Content
            $mail->isHTML(true);                                  // Set email format to HTML
            $mail->Subject = $title;          // 邮箱标题
            $mail->Body    = $content;                         //邮件内容

            $return = $mail->send();                            
        } catch (Exception $e) {
            exception($mail->ErrorInfo, 1001);         // 发送失败代码
        }
     
      
        // 网易邮箱
        try {
            //Server settings 服务器配置
            $mail->SMTPDebug = 0;                      
            $mail->CharSet = 'utf-8';
            $mail->isSMTP();                                          
            $mail->Host       = 'smtp.163.com';                    
            $mail->SMTPAuth   = true;                                  
            $mail->Username   = 'hy*****way@163.com';                     
            $mail->Password   = 'UPO*****JKAXYGK';                              
            $mail->SMTPSecure = 'ssl';       
            $mail->Port       = 465;                                   

            //Recipients  接受信息
            $mail->setFrom('hy*****way@163.com', 'hy*****way'); 
            $mail->addAddress($to);               

            // Content
            $mail->isHTML(true);                                  
            $mail->Subject = $title;
            $mail->Body    = $content;

            $return = $mail->send();
        } catch (Exception $e) {
            exception($mail->ErrorInfo, 1001);
        }
    }
  • 相关阅读:
    [模板]KMP
    [BZOJ] 1833: [ZJOI2010]count 数字计数
    [BZOJ] 1563: [NOI2009]诗人小G
    [BZOJ] 2442: [Usaco2011 Open]修剪草坪
    [LOJ] #2360. 「NOIP2016」换教室
    9.18模拟赛
    [BZOJ] 2006: [NOI2010]超级钢琴
    [BZOJ] 1143: [CTSC2008]祭祀river
    [51Nod] 1218 最长递增子序列 V2
    [BZOJ] 3307: 雨天的尾巴
  • 原文地址:https://www.cnblogs.com/heyongzhen/p/13621813.html
Copyright © 2011-2022 走看看