PHP 列队发email

ps:学习于慕课网视频地址
1:发邮件
github插件地址
示例

<?php

// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//引入类
$rootPath = dirname(__FILE__);//获取项目目录用于定义绝对路径
//Load Composer's autoloader
require $rootPath.'/PHPMailer/src/Exception.php';
require $rootPath.'/PHPMailer/src/PHPMailer.php';
require $rootPath.'/PHPMailer/src/SMTP.php';

require $rootPath.'/PHPMailer/vendor/autoload.php';
//实例化类
$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
    //$mail->SMTPDebug = 2;                                 // Enable verbose debug output如果邮件发送不成功打开此选项用于调试bug
    $mail->isSMTP();                                      // Set mailer to use SMTP设置smtp服务器
    $mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers如smtp.alyu.com
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->CharSet = 'UTF-8';                             //设置邮件中文编码
    $mail->Username = 'user@example.com';                 // SMTP username发送账号
    $mail->Password = 'secret';                           // SMTP password密码
    //$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted加密方式
    //$mail->Port = 587;                                    // TCP port to connect to端口

    //Recipients
    $mail->setFrom('from@example.com', 'Mailer');          //发件地址,人
    $mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient收件地址,人
    //$mail->addAddress('ellen@example.com');               // Name is optional
    $mail->addReplyTo('info@example.com', 'Information');  //回复邮箱
    //$mail->addCC('cc@example.com');                         //抄送
    //$mail->addBCC('bcc@example.com');                       //密送

    //Attachments
    //$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments附件
    //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

    //Content
    $mail->isHTML(true);                                  // Set email format to HTML邮件正文是否有带HTML标签如果有设为true
    $mail->Subject = 'Here is the subject';              //标题
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';//正文
    //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';//没有带HTML内容

    if($mail->send()){
        echo 'Message has been sent';
    }else{
        echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值