• phpmailer配置


    官网文档 参考文献


    较常用配置如下:

    require("PHPMailer_5.2.4/class.phpmailer.php");
    $mail = new phpmailer();
    
    $mail->SMTPDebug = true;                                // 设置是否输出SMTP调试信息
    
    $mail->isSMTP();                                        // 使用SMTP发送
    $mail->Priority = 3;                                    // 邮件优先级, 1高,3普通,5低
    $mail->CharSet = "utf-8";                               // 定义邮件编码
    $mail->ContentType = "text/plain";                      // 文档类型
    $mail->Host = "smtp.163.com";                           // 邮件服务器地址
    $mail->SMTPAuth = true;                                 // 开启SMTP认证
    $mail->Username = 'user@example.com';                   // 登陆SMTP用户名
    $mail->Password = 'secret';                             // 登陆SMTP密码
    $mail->SMTPSecure = 'tls';                              // SMTP加密方式,可选"tls"和"ssl"
    $mail->Port = 587;                                      // 连接的TCP端口
    $mail->Encoding = "base64";                             // 邮件的编码方式,可选:"8bit","7bit","binary","base64",和"quoted-printable"
    
    $mail->From = 'from@example.com';                       // 发件人邮箱
    $mail->FromName = 'Mailer';                             // 发件人姓名
    $mail->addAddress('joe@example.net', 'Joe User');       // 增加收件人地址,参数一为收件人邮箱,参数二可选,为收件人姓名
    $mail->addAddress('ellen@example.com');                 // Name is optional
    $mail->addReplyTo('info@example.com', 'Information');   // 添加回复标签,参数同addAddress
    $mail->addCC('cc@example.com');                         // 添加抄送,参数同addAddress
    $mail->addBCC('bcc@example.com');                       // 添加密送,参数同addAddress
    
    $mail->addAttachment('/var/tmp/file.tar.gz');           // 增加附件,参数一为附件路径,必选,其他参数可选,分别为名称,编码,类型,默认为$name = '', $encoding = 'base64', $type = 'application/octet-stream'
    $mail->addAttachment('/tmp/image.jpg', 'new.jpg');      
    $mail->isHTML(true);                                    // Set email format to HTML
    
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';               // 邮件内容,HTML(如果isHTML为true)或text(如果isHTML为false)
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';    // 当邮件不支持HTML格式显示的文本
    
    if($mail->IsError() || !$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message has been sent';
    }


  • 相关阅读:
    Vue3 模板语法
    Vue 起步
    [原创]CPA、CPC、CPM、CVR、CTR和ROI分别代表什么?
    Redis 线程模型
    BIO和NIO区别以及原理
    kafka简介&kafka安装
    python测试开发django-109.ModelForm模型表单的使用
    HttpRunner2.X 版本和 3.X 版本的区别到底有哪些?(吐血总结!)
    python测试开发django-108.form组件Select下拉框读取数据库内容
    DDD领域驱动设计架构模式:防腐层(Anti-corruption layer)
  • 原文地址:https://www.cnblogs.com/sysuzjz/p/4289308.html
Copyright © 2020-2023  润新知