使用Gmail帐户的XAMPP Sendmail

我试图通过XAMPPconfigurationSendmail发送电子邮件。 在我的sendmail.ini中我有这些设置:

# Set default values for all following accounts. logfile "C:\xampp\sendmail\sendmail.log account Gmail tls on port 587 tls_certcheck off host smtp.gmail.com from myemail@gmail.com auth on user myemail06@gmail.com password mypassword account default : Gmail 

我已经创build了如下的testing脚本:

 $to = "testemail@btinternet.com"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; $headers = "From: myemail06@gmail.com" . "\r\n"; if (mail($to, $subject, $body, $headers)) { echo ("Message successfully sent!"); } else { echo ("Message delivery failed..."); } 

我收到一条消息,说这封电子邮件已发送,但它永远不会到达,并在日志中得到:

sendmail:交付过程中出错:必须首先发出STARTTLS命令。

有人知道这个问题在这里吗?

提前致谢!

GAZ

这是对我有用希望没有人会像我一样燃烧石油来弄清楚这一点。

这是我的sendmail.ini

 [sendmail] smtp_server=smtp.gmail.com smtp_port=25 error_logfile=error.log debug_logfile=debug.log auth_username=myemail@gmail.com auth_password=yourgmailpassword force_sender=myemail@gmail.com 

php / php.ini —-除了sendmail_path和mail.add_x_header之外,基本上都会注释掉

 [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 = postmaster@localhost ; 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\apache\logs\php_mail.log" 

这对我更新sendmail文件(旧的不支持smtp)后,

  • 请访问http://glob.com.au/sendmail/并获取最新的sendmail zip文件
  • 解压缩到桌面并将文件复制到您的\ xampp \ sendmail文件夹中,replace那里的所有文件。实现!
  • 现在打开sendmail.ini并复制粘贴上面显示的内容(先删除文件中的所有内容,或者只是将所有内容注释掉!)
  • 注意:您不需要为此启动Mercury服务器。

当我遇到这个问题时,我正在本地主机上进行密码恢复。 我需要发送用户的密码。 – 你的php看起来很棒

好的,今天,最好的答案不适合我。 但是,这样做:

sendmail.ini中

 [sendmail] smtp_server=smtp.gmail.com smtp_port=587 error_logfile=error.log debug_logfile=debug.log auth_username=****@gmail.com auth_password=******* force_sender=****@gmail.com 

php.ini中:

 [mail function] sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t" 

根据port @: http : //support.google.com/mail/bin/answer.py?hl=zh_CN&answer=13287

我所要做的只是将“允许安全性较低的应用访问您的帐户”切换为开启。 我想这是一个创build应用程序特定的密码的替代scheme。

有关信息, 请访问https://support.google.com/accounts/answer/6010255

为交换机https://www.google.com/settings/security/lesssecureapps

出于安全目的,可能值得将其切换回去。

只是为了增加已经很好的回应。 确保您以pipe理员身份运行XAMPP。 这是为我固定的。

使用Gmail时还有另一个问题。 Gmail现在具有安全性,因此您必须生成特定于应用程序的密码 – 您无法使用您正常访问Gmail的密码。 我通过尝试上面的例子发现了这一点,然后注意到在sendmail文件夹中生成了错误日志。 在错误日志中,我遇到了一条消息指出这一点。

我知道这是一个古老的职位,但只是认为我会分享的事实,以下为我工作。

我目前正在Windows 7 ENT上使用Apache / 2.4.9(Win64)PHP / 5.5.12和MySQL 5.6.17上的WAMP服务器。

我遵循这个教程: http : //blog.techwheels.net/send-email-from-localhost-wamp-server-using-sendmail/

 THIS IS WHAT YOU SENDMAIL SHOULD LOOK LIKE [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=465 ; SMTPS (SSL) support ; auto = use SSL for port 465, otherwise try to use TLS ; ssl = always use SSL ; tls = always use TLS ; none = never try to use SSL smtp_ssl=auto ; 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=mydomain.com ; 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=Your Email Here auth_password=Your Password Here ; 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 force_sender=Your Email Here ; 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=smtp.gmail.com THIS IS WHAT YOU PHP.INI FILE SHOULD LOOK LIKE [mail function] ; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury smtp_server=smtp.gmail.com smtp_port = 465 ; For Win32 only. ; http://php.net/sendmail-from ;sendmail_from = postmaster@localhost ; XAMPP IMPORTANT NOTE (1): If XAMPP is installed in a base directory with spaces (eg c:\program filesC:\xampp) fakemail and mailtodisk do not work correctly. ; XAMPP IMPORTANT NOTE (2): In this case please copy the sendmail or mailtodisk folder in your root folder (eg C:\sendmail) and use this for sendmail_path. ; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder) sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t" ; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the C:\xampp\mailoutput folder ;sendmail_path = "C:\xampp\mailtodisk\mailtodisk.exe" ; 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 

a)更改php.ini在文件path“[驱动器号]:[XAMPP目录] \ php”中findphp.ini。 例如C:\ xampp \ php \ php.ini

在你的php.ini文件中searchsendmail_path ,并在它之前删除分号“;”[我没有path]。

 [mail function] ; For Win32 only. SMTP = smtp.gmail.com smtp_port = 25 ; For Win32 only. ; http://php.net/sendmail-from sendmail_from = [your_gmail_username]@gmail.com sendmail_path = "\"C:\xampplite\sendmail\sendmail.exe\" -t" 

b)更改sendmail.ini在文件path中定位sendmail.ini是“[驱动器号]:[XAMPP目录] \ sendmail”例如C:\ xampp \ sendmail \ sendmail.ini

注释“Mercury”和“免费邮件服务示例”的内容如下所示:

  # Mercury <br/> #account Mercury <br/> #host localhost <br/> #from postmaster@localhost <br/> #auth off <br/> # A freemail service example <br/> #account Hotmail <br/> #tls on <br/> #tls_certcheck off <br/> #host smtp.live .com <br/> #from [exampleuser]@hotmail.com <br/> #auth on <br/> #user [exampleuser]@hotmail .com <br/> #password [examplepassword] <br/> 

C。 添加Gmail帐户。

例:

 account Gmail tls on tls_certcheck off host smtp.gmail.com from [your_gmail_username]@gmail.com auth on account default : Gmail 

d。 重新启动Apache服务器


我没有使用Gmail。 我用我的托pipe帐户。 如果你这样做,确保SMTP设置是正确的。 我的邮件是mail.abc.com而不是smtp.gmail.com。 此代码来自2个网站。 您需要更改这两个文件。 我在X200pp4上运行Xampp 1.73。 除这两个文件以外的所有默认设置。 php.ini和sendmail.ini

这些是最新的Google SMTP服务器要求:

  1. Gmail SMTP服务器地址: smtp.gmail.com
  2. Gmail SMTP密码:( 您的Gmail密码)
  3. Gmail SMTP端口(TLS): 587
  4. Gmail SMTP端口(SSL): 465
  5. 需要Gmail SMTP TLS / SSL: 是的

Google SMTP要求

如果你只是使用SSL,它会变得复杂的所需validation码validationtesting,所以我只是将我的SSL设置为自动,这将尝试TLS时SSL失败。
在这里输入图像描述