• 发送信息到邮箱的第三方扩展库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);
        }
    }
  • 相关阅读:
    GateWay的简单使用
    SpringCloud项目注册到Nacos
    Hystrix整合Gateway
    Nginx配置socket.io集群
    windows搭建git服务
    解决gitLab上新建分支,idea中找不到对应分支问题
    mybatis mapper.xml的特殊操作符
    Chrome添加Axure RP插件
    idea Tomcat部署时没有update classes and resources
    缓存穿透,缓存击穿,缓存雪崩解决方案分析【转载】
  • 原文地址:https://www.cnblogs.com/heyongzhen/p/13621813.html
Copyright © 2020-2023  润新知