怎样使用SMTP服务器发送邮件

2018年10月11日 由 Amon

【问题】

如果2处发送人电邮地址不一致,报错:

There has been an error sending the message. The following From address failed: support@name.com : MAIL FROM command failed,mail from address must be same as authorization user ,501,SMTP server error: MAIL FROM command failed Detail: mail from address must be same as authorization user SMTP code: 501SMTP server error: MAIL FROM command failed Detail: mail from address must be same as authorization user SMTP code: 501 

如果失败,PHPMailer将无法发送电子邮件,报错:

SMTP connect() failed

【方法】

Ping:检查它在哪里?

即使服务器被禁用,所有的服务通常都会对简单的Ping做出响应,所以如果你知道你的DNS是好的,检查服务器是否真的存在:

ping smtp.gmail.com  

返回(按Ctrl + C停止它):

PING gmail-smtp-msa.l.google.com (74.125.133.108): 56 data bytes
64 bytes from 74.125.133.108: icmp_seq=0 ttl=43 time=72.636 ms
64 bytes from 74.125.133.108: icmp_seq=1 ttl=43 time=68.841 ms
64 bytes from 74.125.133.108: icmp_seq=2 ttl=43 time=68.500 ms

telnet:检查它是一个邮件服务器?

可能是某个其他服务正在您尝试连接的SMTP端口上运行。你可以使用这个telnet工具来检查这个(在提交服务端口上连接到gmail):

telnet smtp.gmail.com 587  

返回:

Trying 173.194.67.109...
Connected to gmail-smtp-msa.l.google.com.
Escape character is '^]'.
    220 mx.google.com ESMTP ex2sm16805587wjd.30 - gsmtp

如果端口587不起作用,您可以尝试使用端口465或端口25。但端口25通常不支持加密。

如果它没有输出或者没有输出220,那么你的服务器关闭了,或者你的服务器错了。

经过排查,25端口不通,但 587 端口 畅通,果断使用 587 + tls 。

【QQ邮箱SMTP】

实证成功。

QQ
SMTP
8bit
587
smtp.qq.com
username@qq.com
TOKEN
TLS

【Google邮箱SMTP】

实证未遂。

参考:https://blog.csdn.net/zdgdq/article/details/78518508

https://www.wpbeginner.com/plugins/how-to-send-email-in-wordpress-using-the-gmail-smtp-server/

https://console.developers.google.com/apis/api/gmail.googleapis.com/credentials
https://developers.google.com/gmail/imap/imap-smtp

The outgoing SMTP server, smtp.gmail.com, requires TLS. Use port 465, or port 587 if your client begins with plain text before issuing the STARTTLS command.

Outgoing Mail (SMTP) Server

smtp.gmail.com

Requires SSL: Yes

Requires TLS: Yes (if available)

Requires Authentication: Yes

Port for SSL: 465

Port for TLS/STARTTLS: 587
Full Name or Display Name Your name
Account Name, User name, or Email address Your full email address
Password Your Gmail password

【参考】

参考:https://www.fujieace.com/wordpress/smtp-connect-failed.html
参考:https://since1989.org/whmcs/qq-mail-smtp-error-ssl.html
参考:https://www.xxorg.com/archives/717
参考:https://www.xxorg.com/archives/188
参考:http://www.tuxingzhan.com/wpc/3758.html
参考:https://bbs.csdn.net/topics/391894148

广告位
Sedo.com

评论已关闭.