我目前在 Apache 上运行 PHP 7。我使用 AWS SES 没有任何问题,直到他们现在停止支持 TLS 1.0 和 1.1,现在需要 1.2。我检查了我的 phpinfo() 并且支持 TLS 1.2。
这是我的 PHP 代码:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once("PHPMailer/PHPMailerAutoload.php");
$mail = new PHPMailer;
try {
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = "email-smtp.eu-west-1.amazonaws.com";
$mail->SMTPAuth = true;
$mail->Username = //username
$mail->Password = //password
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->SMTPOptions = [
'ssl' => ['crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT]
];
$mail->addReplyTo("[email protected]");
$mail->addAddress("[email protected]");
$mail->Subject = "test";
$mail->Body = "test";
$mail->send();
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
尽管我在代码中启用了 TLS 版本 1.0 和 1.1,但与 TLS 版本 1.0 和 1.1 直接相关的异常返回的错误不再受支持。有什么建议吗?
刚刚花了一个晚上的时间来解决这个问题,并设置:
$mail->SMTPSecure = "tlsv1.2";
为我们解决了。