简体   繁体   English

Phpmailer 发送邮件而无需 SMTP 身份验证

[英]Phpmailer send mail without SMTP authentication

I am using Phpmailer for sending emails.我正在使用 Phpmailer 发送电子邮件。 Initially it was works fine when I am using SMTP by username and password.最初,当我通过用户名和密码使用 SMTP 时,它工作正常。 If I have tried without SMTP authentication then it returned connection timeout error.如果我在没有 SMTP 身份验证的情况下尝试过,那么它返回连接超时错误。 Here my code is这是我的代码

<?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";
}

?>

The returned error is返回的错误是

SMTP ERROR: Failed to connect to server: Connection timed out (110) SMTP 错误:无法连接到服务器:连接超时 (110)

The mail.log file contains 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.

check your ip is listed on the spamhaus blocklist removal center.检查您的 IP 是否列在 spamhaus 阻止列表删除中心。

https://www.spamhaus.org/query/ip/your-ip-address https://www.spamhaus.org/query/ip/your-ip-address

If it is listed then unlist them by following their procedures.如果已列出,则按照其程序取消列出它们。 It takes some time.这需要一些时间。 remove the SMTP configuration from the code.从代码中删除 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";
}

?>

It works for me.这个对我有用。

//use PHPMAILER to send the mail its working fine and configure the SMTP relay on server properly //使用 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";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM