我无法使用PHPMailer从PHP发送邮件。以前我是通过VB.NET尝试过的,但效果很好。尝试时,它使我陷入错误-
2019-05-13 15:15:46 Connection: opening to smtp-gw.abcd.com:25, timeout=300, options=array ( 'ssl' => array ( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true, ),)
2019-05-13 15:15:46 Connection: opened
2019-05-13 15:15:46 SMTP INBOUND: "220 Mail02.abcd.com ESMTP"
2019-05-13 15:15:46 SERVER -> CLIENT: 220 Mail02.abcd.com ESMTP
2019-05-13 15:15:46 CLIENT -> SERVER: EHLO localhost
2019-05-13 15:15:46 SMTP INBOUND: "250-Mail02.abcd.com"
2019-05-13 15:15:46 SMTP INBOUND: "250-8BITMIME"
2019-05-13 15:15:46 SMTP INBOUND: "250-SIZE 104857600"
2019-05-13 15:15:46 SMTP INBOUND: "250 STARTTLS"
2019-05-13 15:15:46 SERVER -> CLIENT: 250-Mail02.abcd.com250-8BITMIME250-SIZE 104857600250 STARTTLS
2019-05-13 15:15:46 CLIENT -> SERVER: STARTTLS
2019-05-13 15:15:46 SMTP INBOUND: "220 Go ahead with TLS"
2019-05-13 15:15:46 SERVER -> CLIENT: 220 Go ahead with TLS
2019-05-13 15:15:46 CLIENT -> SERVER: EHLO localhost
2019-05-13 15:15:46 SMTP INBOUND: "250-Mail02.abcd.com"
2019-05-13 15:15:46 SMTP INBOUND: "250-8BITMIME"
2019-05-13 15:15:46 SMTP INBOUND: "250 SIZE 104857600"
2019-05-13 15:15:46 SERVER -> CLIENT: 250-Mail02.abcd.com250-8BITMIME250 SIZE 104857600
SMTP Error: Could not authenticate.
2019-05-13 15:15:46 CLIENT -> SERVER: QUIT
2019-05-13 15:15:46 SMTP INBOUND: "221 Mail02.abcd.com"
2019-05-13 15:15:46 SERVER -> CLIENT: 221 Mail02.abcd.com
2019-05-13 15:15:46 Connection: closed
SMTP Error: Could not authenticate.
Message could not be sent. Mailer Error: SMTP Error: Could not authenticate.
这是我的代码块-
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Load Composer's autoloader
require '../vendor/autoload.php';
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 4; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp-gw.abcd.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'jobnotifier@abcd.com'; // SMTP username
$mail->Password = ''; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25; // TCP port to connect to
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
我不太确定我在这里缺少什么。我知道此SMTP服务器身份验证没有任何密码。您也可以在.NET代码中进行检查。这是我来自VB.NET的代码
Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential("jobnotifier@abcd.com", "")
Smtp_Server.Port = 25
Smtp_Server.EnableSsl = False
Smtp_Server.Host = "smtp-gw.abcd.com"
为此寻求帮助。
答案 0 :(得分:0)
服务器说它在STARTTLS之前或之后都不支持身份验证,即existsByProperty()
在任何AUTH
命令之后都没有出现在服务器功能列表中。例如,这是gmail所说的:
EHLO
由于您的服务器似乎不允许身份验证(并且您的VB脚本可能发现了该身份,并且也不想进行尝试),因此请告诉您的脚本不要使用它:
250-smtp.gmail.com at your service, [88.184.221.3]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
此外,为什么要禁用TLS证书验证?您需要有一个非常这样做的充分理由-而不仅仅是“使之起作用”;如果您的TLS配置损坏,请修复它,不要只是抑制错误。