/*
* 第三方发邮件接口 https://luckycola.com.cn/public/docs/shares/api/mail.html
{
"ColaKey": "i6qNeQszeSD6zf16988I2YaRNIMz",// 官网获取
"tomail": "1537@163.com",// 邮件发给谁?
"fromTitle": "我是邮件标题",// 邮件标题
"subject": "我是邮件主题",
// 邮件系统授权码,参考[获取文档]:https://blog.csdn.net/qq_48896417/article/details/133903185?spm=1001.2014.3001.5501
"smtpCode": "GNNSC*******TWU",
// 开启授权码对应的授权邮箱
"smtpEmail": "example@163.com",
// 授权邮箱的类型, 可取值是 qq 或 163 或 126
"smtpCodeType": "163",
"isTextContent": false,// 邮件内容是否是纯文本形式
"content": "<div style='color: red'>我是邮件内容(因为isTextContent=false所以我可以解析html标签,是红色的)</div>",// 邮件内容
}
*/
public function sendMail($toemail = "", $subject = "", $content = "", $fromUserInfo = "admin") {
$params = [];
$params["ColaKey"] = "xx";
$params["tomail"] = $toemail;
$params["fromTitle"] = $fromUserInfo;
$params["subject"] = $subject;
$params["content"] = $content;
if (strpos($toemail,"@163") !== false) {
$params["smtpCode"] = "xxx";//授权码有效期180天
$params["smtpEmail"] = "xxx@163.com";
$params["smtpCodeType"] = "163";
} elseif (strpos($toemail,"@qq") !== false) {
$params["smtpCode"] = "xxx";
$params["smtpEmail"] = "xx@qq.com";
$params["smtpCodeType"] = "qq";
}
$mail_url = "https://luckycola.com.cn/tools/customMail";
$rs_str = curl($mail_url, $params);
$rs = json_decode($rs_str,true);
if (isset($rs["code"]) && $rs["code"] == 0) {
$this->logfile("发送邮件成功 --> ". $rs_str);
} else {
$this->logfile("发送邮件失败 --> ". $rs_str);
}
// 使用php内置mail函数发邮件,需要启动postfix服务(systemctl start postfix)且 放行外网25端口
// ini_set("SMTP", "smtp.163.com");
// ini_set("smtp_port", "25");
// $tomail = "xx@qq.com"; // 收件人邮箱地址
// $title = "邮件主题";
// $content = "邮件内容";
// $sendermail = "sender@example.com";
// $headers = "From: {$sendermail}"; // 发件人邮箱地址
//
// //发送邮件
// $rs = mail($tomail, $title, $content, $headers);
// if ($rs) {
// exit("ok");
// } else {
// exit("邮件发送失败");
// }
}
// 调用
// $tomail = "xx@qq.com"; // 收件人邮箱地址
// $subject = "邮件主题";
// $content = "邮件内容";
// $fromUserInfo = "发送方";
// $this->sendMail($toemail, $subject, $content, $fromUserInfo);
版权属于:
dafenqi
作品采用:
《
署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
》许可协议授权
Warning: Trying to access array offset on value of type null in /www/wwwroot/testblog.58heshihu.com/usr/themes/Joe-master/core/function.php on line 247
1
2