php - php邮件功能工作PHPMailer不工作
问题描述
我的网站上的邮件功能和 PHPMailer 包有问题。
起初我尝试使用邮件功能发送电子邮件:
mail('myemail@gmail.com', 'Test Mail - Raw', 'Test message.');
邮件已成功发送,但未在我的收件箱或垃圾邮件中收到。
经过大量搜索后,我在邮件功能中添加了一个标题:
mail('myemail@gmail.com', 'Test Mail - Without Reply-To', 'Test message', "From: mahdyaslami <myemail@gmail.com>");
最后我在垃圾邮件中发现我发送的邮件带有黄色警告。
我想使用 PHPMailer 包,因为我想附加文件并添加此代码。
protected function send($from, $to, $subject, $body, $altBody, $attachmentPath): bool
{
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->SMTPSecure = 'ssl';
$mail->isSMTP();
$mail->isSendmail();
$mail->setFrom($from);
$mail->addReplyTo($from, $from);
$mail->addAddress($to);
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AltBody = $altBody;
if ($attachmentPath) {
$mail->addAttachment($attachmentPath);
}
$mail->send();
return true;
}
但我有第一个问题,我的邮件已成功发送,但我无法在收件箱或垃圾邮件中收到邮件。
解决方案
推荐阅读
- python - GET 404 未能在烧瓶引导程序中加载资源错误
- php - PHP Wamp 服务器 - 一台服务器上有 2 个 SSL 证书
- validation - Golang 验证器:structExcept
- javascript - React / PrimeReact 应用程序未使用 JSON 从 Web 服务呈现数据表内容
- swift - UIView 未使用模型初始化
- php - 在 Symfony 中反序列化对象的索引数组
- sql - 选择一行Oracle中的所有值(所有行)
- java - 更新了错误“JDK7u25 Codebase manifest 属性应该用于限制 JAR 再利用。请设置 manifest.custom.codebase”的解决方案
- r - 应用 fGarch 包拟合简单 GARCH 模型时的警告消息
- c# - VS2019社区升级到专业版报错CS0579