我正在使用Phpmailer发送电子邮件。最初,当我通过用户名和密码使用SMTP时它工作正常。如果我尝试过没有SMTP身份验证,则会返回连接超时错误。我的代码是
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = "relay-hosting.secureserver.net";
$mail->Port = 25;
$mail->SMTPAuth = false;
$mail->SMTPSecure = false;
$mail->setFrom('xxxx@domainname.com', 'First Last');
$mail->addAddress("xxxx@domainname.com", "Recepient Name");
$mail->addReplyTo("xxxx@domainname.com", "Reply");
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
?>
返回的错误是
SMTP错误:无法连接到服务器:连接超时(110)
mail.log文件包含
host smtp.secureserver.net[68.178.213.203] refused to talk to
me: 554 p3plibsmtp03-06.prod.phx3.secureserver.net bizsmtp
IB105. Connection refused. <ip address> is listed on the
Exploits Block List (XBL)<http://www.spamhaus.org/query/ip/ip
address> Please visit http://www.spamhaus.org/xbl/ for
more information.
答案 0 :(得分:1)
检查你的ip是否列在spamhaus blocklist删除中心。
https://www.spamhaus.org/query/ip/your-ip-address
如果列出,则按照其程序取消列出。这需要一些时间。从代码中删除SMTP配置。
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->setFrom('xxxx@domainname.com', 'First Last');
$mail->addAddress("xxxx@domainname.com", "Recepient Name");
$mail->addReplyTo("xxxx@domainname.com", "Reply");
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
?>
它对我有用。
答案 1 :(得分:0)
//使用PHPMAILER发送邮件工作正常并在服务器上正确配置SMTP中继
require_once "vendor/autoload.php"; //PHPMailer Object
use PHPMailer\PHPMailer\PHPMailer;
$mail = new PHPMailer;
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = "smtp.xxxxxxx.com";
$mail->SMTPAuth = false;
$mail->Port = 25;
$mail->From = "xxx@xxxxx.com";
$mail->FromName = "xxxxxxxx";
$mail->addAddress("xxxxx@xxxxxxxx.com", "Recepient Name");
$mail->isHTML(true);
$mail->Subject = "Subject is here";
$mail->Body = "Hello, <br>test body ";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}