1、使用 composer 下载 phpmailercomposer require phpmailer/phpmailer
2、自定义 Mailer.php 文件,我使用的是TP5.1的框架测试,可自定义了参数弄的有点乱,大家将就下<?php
namespace util;
use PHPMailer\PHPMailer\PHPMailer;
class Mailer
{
// 编码格式为utf8,不设置编码的话,中文会出现乱码
protected $charSet = 'utf-8';
// 发送方的SMTP服务器地址,QQ邮箱为:smtp.qq.com
protected $host = 'smtp.163.com';
// 163邮箱的ssl协议方式端口号是465/994 QQ邮箱的ssl协议方式端口号是465/587
protected $port = 465;
// 是否使用身份验证,默认false
protected $smtpAuth = true;
// 发送方的邮箱用户名,就是你申请163的SMTP服务使用的163邮箱,或者QQ邮箱等
protected $mailUsername = '';
// 发送方的邮箱密码,注意用163邮箱这里填写的是“客户端授权密码”而不是邮箱的登录密码!QQ邮箱同理,如果没有授权码就是邮箱密码
protected $mailPassword = '';
// 使用ssl协议方式
protected $smtpSecure = 'ssl';
// 错误调试,默认关闭
protected $smtpDebug = 0;
// 发送邮件地址
protected $mailFrom = '';
// 发送名称
protected $mailFromname = '';
// 回复邮箱地址
protected $replyMail = '';
/**
* 初始化发送邮件参数
* @param array $conf
*/
public function __construct($conf = [])
{
if (!empty($conf)) {
$this->charSet = !empty($conf['charSet']) ? $conf['charSet'] : $this->charSet;
$this->host = !empty($conf['host']) ? $conf['host'] : $this->host;
$this->port = !empty($conf['port']) ? $conf['port'] : $this->port;
$this->smtpAuth