即使在连续试验了两天..我坚持“邮件发送失败”错误无法通过PHP的mail发送邮件()函数获取例外 - 必须发出STARTTLS命令第一
尽管许多解决方案那里堆栈溢出本身,但我还是问这个becoz他们没有帮助
预 - (如果需要) 使用的是Windows 10,PHP 5.5.12,阿帕奇2.4.9
我方法
1)下载SMTP
2)配置smtp.ini
3)配置的php.ini
4)配置我的Gmail帐户
注意 我有尝试所有可能的方法和超过15个教程,直到现在得到这个邮件的事情在过去2天内完成...
但:( 还我已经设置我的Gmail帐户,允许不够安全的应用,支持IMAP和功能已停用两步验证
随信附上错误日志文件和我的SMTP和的php.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
; 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=none
; 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=localhost
; 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
[email protected]
auth_password=mypasswordhere
; if your smtp server uses pop3 before smtp authentication, modify the
; following three lines. do not enable unless it is required.
pop3_server=
pop3_username=
pop3_password=
; force the sender to always be the following email address
; this will only affect the "MAIL FROM" command, it won't modify
; the "From: " header of the message content
[email protected]
; force the sender to always be the following email address
; this will only affect the "RCTP TO" command, it won't modify
; the "To: " header of the message content
force_recipient=
; 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
我收到以下错误日志
16/03/19 09:44:36 ** --- MESSAGE BEGIN ---
16/03/19 09:44:36 ** To: [email protected]
16/03/19 09:44:36 ** Subject: Testing sendmail.exe
16/03/19 09:44:36 ** X-PHP-Originating-Script: 0:tt1.php
16/03/19 09:44:36 ** From: [email protected]
16/03/19 09:44:36 ** MIME-Version: 1.0
16/03/19 09:44:36 ** Content-type: text/html; charset=utf-8
16/03/19 09:44:36 **
16/03/19 09:44:36 ** Hi, you just received an email using sendmail!
16/03/19 09:44:36 ** --- MESSAGE END ---
16/03/19 09:44:36 ** Connecting to smtp.gmail.com:587
16/03/19 09:44:36 ** Connected.
16/03/19 09:44:37 << 220 smtp.gmail.com ESMTP wx3sm24328300pab.25 - gsmtp<EOL>
16/03/19 09:44:37 >> EHLO localhost<EOL>
16/03/19 09:44:37 << 250-smtp.gmail.com at your service, [115.248.50.20]<EOL>250-SIZE 35882577<EOL>250-8BITMIME<EOL>250-STARTTLS<EOL>250-ENHANCEDSTATUSCODES<EOL>250-PIPELINING<EOL>250-CHUNKING<EOL>250 SMTPUTF8<EOL>
16/03/19 09:44:37 ** Authenticating as [email protected]
16/03/19 09:44:37 >> MAIL FROM: <[email protected]><EOL>
16/03/19 09:44:37 << 530 5.7.0 Must issue a STARTTLS command first. wx3sm24328300pab.25 - gsmtp<EOL>
16/03/19 09:44:37 ** Disconnecting from smtp.gmail.com:587
16/03/19 09:44:37 ** Disconnected.
16/03/19 09:44:37 ** Disconnected.
16/03/19 09:44:37 ** Must issue a STARTTLS command first. wx3sm24328300pab.25 - gsmtp<EOL>
这里是php.ini中的片段
[mail function]
; For Win32 only.
; http://php.net/smtp
;SMTP = localhost
; http://php.net/smtp-port
;smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = [email protected]
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "C:\wamp\sendmail\sendmail.exe -t -i"
; 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 = On
; The path to a log file that will log all mail() calls. Log entries include
; the full path of the script, line number, To address and headers.
;mail.log =
; Log mail to syslog (Event Log on NT, not valid in Windows 95).
;mail.log = syslog
4)我的PHP代码
<?php
$to = '[email protected]';
$subject = 'Testing sendmail.exe';
$message = 'Hi, you just received an email using sendmail!';
$headers = 'From: [email protected]' . "\r\n" .
'MIME-Version: 1.0' . "\r\n" .
'Content-type: text/html; charset=utf-8';
if(mail($to, $subject, $message, $headers))
echo "Email sent";
else
echo "Email sending failed";
?>
嗨Synchro, 感谢您的回复...但正如我在我的问题中提到的那样,我尝试了每一个可能的技巧。 我的意思是,我试过smtp_ssl = auto和smtp_ssl = tls 但他们都没有工作.. 请指出其他的东西... (如果有道理) – eRaisedToX