【发布时间】:2021-04-22 11:15:07
【问题描述】:
我想从服务器发送电子邮件(ubuntu server 11.10 php version 5.3.x)但我收到这样的错误:
2021-01-18 05:15:24 Connection: opening to mail.domain.co.id:587, timeout=300, options=array ()
2021-01-18 05:15:24 Connection: opened
2021-01-18 05:15:24 SERVER -> CLIENT: 421 4.7.0 Connection refused
2021-01-18 05:15:24 CLIENT -> SERVER: EHLO reporting
2021-01-18 05:15:24 SERVER -> CLIENT:
2021-01-18 05:15:24 SMTP ERROR: EHLO command failed:
2021-01-18 05:15:24 SMTP NOTICE: EOF caught while checking if connected
2021-01-18 05:15:24 Connection: closed
2021-01-18 05:15:24 SMTP Error: Could not connect to SMTP host.
2021-01-18 05:15:24 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer wiki/Troubleshooting
Message could not be sent. Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
在我的 php 代码中:
<?php
require 'PHPMailer/PHPMailerAutoload.php';
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer();
//Server settings
$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'mail.domain.co.id'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'donotreply@domain.co.id'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('donotreply@domain.co.id', 'Mailer');
$mail->addAddress('fajar.a@domain.co.id', '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';
if(!$mail->send()){
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
} else {
echo "Message has been sent";
}
?>
使用相同的 php 代码,我尝试在 localhost 中运行此代码并成功。仅供参考,我正在使用电子邮件开发应用程序通知,并且在开发过程中尝试发送许多电子邮件,服务器中是否有任何问题或某些东西阻止了我在服务器中的 SMTP 连接?
感谢您的帮助
【问题讨论】:
-
我也面临同样的挑战。
标签: php apache ubuntu phpmailer