发送消息时出错:SMTP 连接()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

问题描述 投票:0回答:1

我的网站使用 smtp.gmail.com 发送电子邮件。服务已停止。发送消息时出错:SMTP 连接() 失败。 https://github.com/PHPMailer/PHPMailer/wiki/疑难解答

该脚本可以正常运行数月。

require '/var/www/html/vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
$mail = new PHPMailer();
$mail->isSMTP();                                            // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';                 // Specify main mail server
$mail->Port = 587;
$mail->SMTPAuth = true;                                     // Enable SMTP authentication
$mail->Username = '[email protected]';                     // SMTP username
$mail->Password = 'b1oema57_removed'; 
$mail->setFrom('[email protected]', 'Fanmail.biz');
$mail->addReplyTo('[email protected]', 'Reply To Name');
$mail->addAddress($email2);
$mail->Subject = "Fanmail Alerts - Password & Activation Link";
$mail->Body = "Hello,...";
if(!$mail->send()) {
$message3 = "Error sending message: " . $mail->ErrorInfo;
else {
$message3 = "<font color=\"#FF0000\">Inactivated Account.<br>Password and an activation link have been     sent to $email2.</font>";
}</sub>

我已就该问题联系了我的托管公司。这是他们的回复:

我已经确认通过telnet连接到端口587上的“smtp.gmail.com”成功。这表明服务器运行正常,并且您的服务器和 Gmail 服务器之间不存在连接问题。我建议您联系 Gmail 支持人员,寻求有关您可能遇到的任何 SMTP 相关问题的帮助,因为他们最有能力解决其服务的具体问题。

[root@ded93 ~]# telnet smtp.gmail.com 587
Trying 142.251.116.109...
Connected to smtp.gmail.com.
Escape character is '^]'.
220 smtp.gmail.com ESMTP 46e09a7af769-7155686c95bsm478175a34.73 - gsmtp
smtp gmail-api
1个回答
0
投票

我添加了 $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;到脚本,错误是相同的:

Error sending message_4: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting" 

$mail = new PHPMailer();
$mail->isSMTP();                                          
$mail->Host = 'smtp.gmail.com';                 
$mail->Port = 587;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->SMTPAuth = true;                                      
$mail->Username = '[email protected]';                     
$mail->Password = 'b1oema57_Removed'; 
$mail->setFrom('[email protected]', 'Fanmail.biz');
$mail->addReplyTo('[email protected]', 'Reply To Name');
$mail->addAddress($email2);
$mail->Subject = "Fanmail Alerts - Password & Activation Link";
$mail->Body = "Hello";

if(!$mail->send()) {
$message3 = "Error sending message: " . $mail->ErrorInfo;
© www.soinside.com 2019 - 2024. All rights reserved.