1 Star 0 Fork 8

urchin/PHPWebHook

forked from Phyuany/PHPWebHook 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
MailSender.php 2.16 KB
一键复制 编辑 原始数据 按行查看 历史
kotlindev 提交于 2020-08-07 23:18 . init
<?php
require_once 'vendor/autoload.php';
// 引入composer依赖
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
class MailSender
{
/*
* SMTP配置
* */
private $smtp_host = 'smtp.exmail.qq.com';//SMTP服务器地址
private $smtp_from = '极客开发者-管理员';//发送者
private $smtp_username = 'admin@jkdev.cn';//邮箱账号
private $smtp_password = '';//邮箱密码
private $smtp_port = '465';//端口号
/**
* 发送邮件对象
* @param $addresses
* @param $subject
* @param $body
* @return PHPMailer
* @throws Exception
*/
public function obtainEmailSender(array $addresses, $subject, $body)
{
$mailSender = new PHPMailer(true);
$mailSender->CharSet = 'UTF-8';
//Server settings
$mailSender->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
$mailSender->isSMTP(); // Send using SMTP
$mailSender->Host = $this->smtp_host; // Set the SMTP server to send through
$mailSender->SMTPAuth = true; // Enable SMTP authentication
$mailSender->Username = $this->smtp_username; // SMTP username
$mailSender->Password = $this->smtp_password; // SMTP password
$mailSender->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
$mailSender->Port = $this->smtp_port; // TCP port to connect to
//Recipients
$mailSender->setFrom($this->smtp_username, $this->smtp_from);
foreach ($addresses as $index => $address) {
$mailSender->addAddress($address); // Name is optional
}
// Content
$mailSender->isHTML(true); // Set email format to HTML
$mailSender->Subject = $subject;
$mailSender->Body = $body;
//返回邮件对象
return $mailSender;
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/urchinstarz/PHPWebHook.git
git@gitee.com:urchinstarz/PHPWebHook.git
urchinstarz
PHPWebHook
PHPWebHook
master

搜索帮助