php - 无法从php发送邮件
问题描述
我们正在尝试从 bigrock 上的 PHP 程序发送邮件,邮件服务器在 Digital Ocean 上 但是邮件没有被发送 指定邮件服务器的方式有什么问题吗?
<?php
require 'Exception.php';
require 'PHPMailer.php';
//Load Composer's autoloader
require 'SMTP.php';
$mail = new PHPMailer\PHPMailer\PHPMailer(true); // Passing true enables
exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'mail.mandify.in'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'ABC@mandify.in'; // SMTP username
$mail->Password = 'XYZ'; // SMTP password
$mail->SMTPSecure = 'STARTTLS'; // Enable TLS encryption, ssl also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('ABC@mandify.in', 'Mailer');
$mail->addAddress('QWERTY@gmail.com', 'Joe User'); // Add a recipient
//Content
$mail->isHTML(true); // Set email format to HTML
$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';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
?>
同样的代码也为 bigrock 上的邮件服务器运行(与执行相同的服务器),但这也不起作用
这是错误消息:
连接失败。错误 #2:stream_socket_enable_crypto():SSL 操作失败,代码为 1。OpenSSL 错误消息:错误:14090086:SSL 例程:ssl3_get_server_certificate:证书验证失败
根据服务器管理团队的反馈,代码似乎有问题。
解决方案
这可能是配置问题或缺少依赖项的指示。尝试避免证书验证失败的一件事是配置以下内容:
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
]
推荐阅读
- gradle - 如何使用单个变更集 liquibase 动态创建模式
- javascript - 作为多个已解决的承诺的结果,如何创建一个列表并创建填充列表的变量?
- java - Java 客户端-服务器编程:客户端之间的共享内存
- java - Windows 10 上的 Sonarqube 无法启动
- python - Python Pandas:Dataframe.loc[] vs dataframe[] 行为差异?
- arrays - SnapLogic - 在 Mapper 中更改数组元素
- javascript - 配置VueJS页面(vue.config.js中的多个页面)MPA
- c# - AJAX.BeginForm - OnFailure 未收到 JSON 响应
- sql - 同一查询中的 COUNT、GROUP BY 和 COUNT 的总和
- c# - 使用 HTMLAgility Pack 解析网站时出现意外结果