我试图配置后缀以使用Azure 虚拟机上托管的 centos 7 上的 phpmailer 发送 smtp 电子邮件。(防火墙/selinux 已禁用(
我的问题是当我尝试使用phpmailer时,我收到"客户端:503 5.5.1 错误:未启用身份验证 SMTP 错误"。
2018-06-02 16:07:17 SERVER -> CLIENT: 220 myserver.com ESMTP Postfix 2018-06-02 16:07:17 CLIENT -> SERVER: EHLO myserver.com 2018-06-02 16:07:17 SERVER -> CLIENT: 250-myserver.com 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN 2018-06-02 16:07:17 CLIENT -> SERVER: AUTH LOGIN 2018-06-02 16:07:17 SERVER -> CLIENT: 503 5.5.1 Error: authentication not enabled 2018-06-02 16:07:17 SMTP ERROR: AUTH command failed: 503 5.5.1 Error: authentication not enabled 2018-06-02 16:07:17 CLIENT -> SERVER: QUIT 2018-06-02 16:07:17 SERVER -> CLIENT: 221 2.0.0 Bye 2018-06-02 16:07:17 SMTP connect() failed. Mailer Error: SMTP connect() failed.
这是我的phpmailser邮件设置。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>PHPMailer - SMTP email test</title>
</head>
<body>
<?php
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require 'PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer();
$mail->isSMTP();
$host = "localhost";
$username = "captan@myserver.com";
$password = "XUF9?YMd";
$Port = 25;
$mail->FromName = "Mail from rovo ";
$mail->From = "captan@myserver.com";
$mail->Host = $host;
$mail->Port = $Port;
#$mail->SMTPSecure = 'ssl'; //optional
$mail->SMTPAuth = true;
$mail->Username = $username;
$mail->Password = $password;
$mail->AddAddress("mymail@yahoo.com");
$mail->Subject = 'PHPMailer - SMTP email test';
$mail->Body = 'This is a plain-text message body';
$mail->SMTPDebug = 2;
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
</body>
</html>
由于上述错误,我无法使用phpmailer,但我可以成功地远程登录到服务器中的端口25
[root@myserver ~]# telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 myserver.com ESMTP Postfix
后会议 -M结果像这样
smtp inet n - n - - smtpd
465 inet n - n - - smtpd
587 inet n - n - - smtpd
25 inet n - n - - smtpd
submission inet n - - - - smtpd -o syslog_name=postfix/submission -o smtpd_sasl_auth_enable=yes -o milter_macro_daemon_name=ORIGINATING -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
smtps inet n - n - - smtpd -o syslog_name=postfix/smtps -o smtpd_sasl_auth_enable=yes -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject -o milter_macro_daemon_name=ORIGINATING
pickup unix n - n 60 1 pickup
cleanup unix n - n - 0 cleanup
qmgr unix n - n 300 1 qmgr
tlsmgr unix - - n 1000? 1 tlsmgr
rewrite unix - - n - - trivial-rewrite
bounce unix - - n - 0 bounce
defer unix - - n - 0 bounce
trace unix - - n - 0 bounce
verify unix - - n - 1 verify
flush unix n - n 1000? 0 flush
proxymap unix - - n - - proxymap
proxywrite unix - - n - 1 proxymap
smtp unix - - n - - smtp
relay unix - - n - - smtp
showq unix n - n - - showq
error unix - - n - - error
retry unix - - n - - error
discard unix - - n - - discard
local unix - n n - - local
virtual unix - n n - - virtual
lmtp unix - - n - - lmtp
anvil unix - - n - 1 anvil
scache unix - - n - 1 scache
后会议 -n 结果
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5
html_directory = no
inet_interfaces = localhost
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
mydestination = $myhostname, localhost.$mydomain, localhost
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = no
sample_directory = /usr/share/doc/postfix-2.10.1/samples myhostname = myserver.com mydomain = myserver.com myorigin = win home_mailbox = mail/ mynetworks = 127.0.0.0/8 inet_interfaces = all inet_protocols = all inet_interfaces = localhost mydestination = myserver.com, localhost.com, localhost, com smtpd_sasl_type = dovecot smtpd_sasl_path = private/auth smtpd_sasl_local_domain = smtpd_sasl_security_options = noanonymous broken_sasl_auth_clients = yes smtpd_sasl_auth_enable = yes smtp_sasl_auth_enable = yes smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination smtp_tls_security_level = may smtpd_tls_security_level = may smtp_tls_note_starttls_offer = yes smtpd_tls_loglevel = 1 smtpd_tls_key_file = /etc/postfix/ssl/server.key smtpd_tls_cert_file = /etc/postfix/ssl/server.crt smtpd_tls_received_header = yes smtpd_tls_session_cache_timeout = 3600s tls_random_source = dev:/dev/urandom
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
unknown_local_recipient_reject_code = 550
请指导我解决问题。 谷歌搜索和故障排除几个小时,但没有线索。
大多数服务器不允许在没有加密的情况下进行身份验证,并且您尚未对其进行配置 - 服务器没有通告任何AUTH机制,因此PHPMailer只是尝试一下。
不允许在端口 25 上发送也是正常的,这就是 SMTP 提交协议存在的原因;在端口 587 上使用SMTPSecure = 'tls'
提交,或在端口 465 上使用ssl
提交。
或者,既然它是本地主机,为什么还要费心进行身份验证呢?试试$mail->SMTPAuth = false;