通过 Xampp 发送本地电子邮件时出现 Gmail 错误(必须发出 STARTTLS 命令)
Posted
技术标签:
【中文标题】通过 Xampp 发送本地电子邮件时出现 Gmail 错误(必须发出 STARTTLS 命令)【英文标题】:Gmail error when sending local email via Xampp (must issue a STARTTLS command) 【发布时间】:2016-04-24 03:07:13 【问题描述】:我安装了 XAMPP 服务器,现在我正尝试通过 gmail 服务器发送我的本地电子邮件。为此,我关注了this link,并将我的 php.ini 和 sendmail.ini 更改如下:
php.ini
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 587
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = xxx.xxx@gmail.com
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =
; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = Off
; Log all mail() calls including the full path of the script, line #, to address and headers
;mail.log = "C:\xampp\php\logs\php_mail.log"
sendmail.ini
; configuration for fake sendmail
; if this file doesn't exist, sendmail.exe will look for the settings in
; the registry, under HKLM\Software\Sendmail
[sendmail]
; you must change mail.mydomain.com to your smtp server,
; or to IIS's "pickup" directory. (generally C:\Inetpub\mailroot\Pickup)
; emails delivered via IIS's pickup directory cause sendmail to
; run quicker, but you won't get error messages back to the calling
; application.
smtp_server=smtp.gmail.com
; smtp port (normally 25)
smtp_port=587
; the default domain for this server will be read from the registry
; this will be appended to email addresses when one isn't provided
; if you want to override the value in the registry, uncomment and modify
;default_domain=local
; log smtp errors to error.log (defaults to same directory as sendmail.exe)
; uncomment to enable logging
error_logfile=error.log
; create debug log as debug.log (defaults to same directory as sendmail.exe)
; uncomment to enable debugging
debug_logfile=debug.log
; if your smtp server requires authentication, modify the following two lines
auth_username=xxx.xxx@gmail.com
auth_password=xxx
; if your smtp server uses pop3 before smtp authentication, modify the
; following three lines
;pop3_server=
;pop3_username=
;pop3_password=
; to force the sender to always be the following email address, uncomment and
; populate with a valid email address. this will only affect the "MAIL FROM"
; command, it won't modify the "From: " header of the message content
force_sender=xxx.xxx@gmail.com
; sendmail will use your hostname and your default_domain in the ehlo/helo
; smtp greeting. you can manually set the ehlo/helo name if required
;hostname=localhost
使用这些设置,我将从 gmail 服务器收到以下错误:
16/01/18 20:47:28 ** Connecting to smtp.gmail.com:587
16/01/18 20:47:28 ** Connected.
16/01/18 20:47:28 << 220 smtp.gmail.com ESMTP w80sm17190895wme.17 - gsmtp<EOL>
16/01/18 20:47:28 >> EHLO SamClauw<EOL>
16/01/18 20:47:28 << 250-smtp.gmail.com at your service, [213.118.20.101]<EOL>250-SIZE 35882577<EOL>250-8BITMIME<EOL>250-STARTTLS<EOL>250-ENHANCEDSTATUSCODES<EOL>250-PIPELINING<EOL>250-CHUNKING<EOL>250 SMTPUTF8<EOL>
16/01/18 20:47:28 ** Authenticating as xxx.xxx@gmail.com
16/01/18 20:47:28 >> MAIL FROM: <xxx.xxx@gmail.com><EOL>
16/01/18 20:47:28 << 530 5.7.0 Must issue a STARTTLS command first. w80sm17190895wme.17 - gsmtp<EOL>
16/01/18 20:47:28 ** Disconnecting from smtp.gmail.com:587
16/01/18 20:47:28 ** Disconnected.
16/01/18 20:47:28 ** Disconnected.
16/01/18 20:47:28 ** Must issue a STARTTLS command first. w80sm17190895wme.17 - gsmtp<EOL>
如您所见:我已经建立了连接,但在那之后,STARTTLS 命令或其他东西出现了问题。
我用谷歌搜索了很多次:
XAMPP 的管理员权限 smtp 端口 25 和 465 ssl://smtp.gmail.com 而不是 smtp.gmail.com 我的 gmail 帐户的安全性较低 ...但这些都无济于事。有没有人遇到同样的问题并且可以解决这个问题?我应该更改什么设置才能使其最终起作用?
谢谢 ;)
【问题讨论】:
你有没有得到这个工作?我已经尝试了相同的列表来使其正常工作,但我仍然无法发送电子邮件。希望这篇文章有答案,但你已经尝试了我所做的一切,甚至降低了我的 gmail 帐户的安全性。 【参考方案1】:我曾经遇到过同样的问题,所以我尝试通过 TLS 进行连接,并且成功了。 这是我的邮件输出:
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
我正在使用 phpmailer (https://github.com/PHPMailer/PHPMailer/),所以你应该尝试连接到主机:tls://smtp.gmail.com:587。
【讨论】:
当我将 SMTP 的 php.ini 值更改为“tls://smtp.gmail.com”并将 smtp_server 的 sendmail.php 值更改为“tls://smtp.gmail.com” ,我的调试日志中出现以下错误:Connecting to tls:25 - 16/01/20 19:21:50 ** Disconnected。 - 16/01/20 19:21:50 ** 已断开连接。 - 16/01/20 19:21:50 ** 已断开连接。 - 20 年 16 月 1 日 19:21:50 ** 套接字错误 # 11004在 sendmail.ini 中设置 smtp_ssl 为自动
; SMTPS (SSL) support
; auto = use SSL for port 465, otherwise try to use TLS
; ssl = alway use SSL
; tls = always use TLS
; none = never try to use SSL
smtp_ssl=auto
【讨论】:
以上是关于通过 Xampp 发送本地电子邮件时出现 Gmail 错误(必须发出 STARTTLS 命令)的主要内容,如果未能解决你的问题,请参考以下文章
来自 php 表单的问题/错误,用于使用 php-mailer 库通过本地主机 Xampp 发送电子邮件
如何配置 XAMPP PHP 通过安全 smtp 我的 ISP 从本地主机发送邮件
尝试通过电子邮件发送多个附件时出现 ActivityNotFoundException