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);
        }
    }
  • 相关阅读:
    HDU2045_LELE的RPG难题
    HDU2050_折线分割平面数
    HDU1159_最长公共子序列
    ASP.NET 页生命周期概述
    Hadoop编译
    .Hadoop NameNode单点问题解决方案之二 AvatarNode 部署
    Pig调试环境
    HADOOP综合应用架构之一 配置Secondarynamenode在另一台机器运行
    JAVA采用远程连接Hive
    Windows Server 2003 FTP服务器配置详解
  • 原文地址:https://www.cnblogs.com/heyongzhen/p/13621813.html
Copyright © 2011-2022 走看看