PHP Sendmail 在 Windows xampp 中失败

标签 php xampp sendmail sendmail.exe

我正在尝试通过我的 gmail 帐户在 Windows 中发送邮件,我已经配置了我的 php.ini :

SMTP=smtp.gmail.com
smtp_port=587
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="681b0d060c05090104370e1a0705550209011b0906091b5a280f05090104460b0705" rel="noreferrer noopener nofollow">[email protected]</a>
sendmail_path="\"C:\xampp\sendmail\sendmail.exe\" -t"

and sendmail.ini :
smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=auto
error_logfile=error.log
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d3b2a6a7bb8ca6a0b6a1bdb2beb6eeb0bcbdb5bab7b6bda7bab2bf93b4beb2babffdb0bcbe" rel="noreferrer noopener nofollow">[email protected]</a>
auth_password=my-password-confident
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d5b3baa7b6b08aa6b0bbb1b0a7e8b6babbb3bcb1b0bba1bcb4b995b2b8b4bcb9fbb6bab8" rel="noreferrer noopener nofollow">[email protected]</a>

这是我的代码:

<?php
// The message
$message = "Line 1\r\nLine 2\r\nLine 3";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");

// Send
$send = mail('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c5afa4acb6a4aba4b6f785a2a8a4aca9eba6aaa8" rel="noreferrer noopener nofollow">[email protected]</a>', 'My Subject', $message);
if ($send) {
    echo "send";
}
else {
echo "fail";}
?>

我还改变了我的谷歌安全性变得不太安全 我不知道为什么,有人帮助我吗?

最佳答案

我不确定您是否使用 Windows 8,但如果您使用 Windows 8,则必须执行以下操作 -

1)在 PHP.ini 中,使电子邮件部分如下所示

; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
SMTP = localhost
smtp_port = 465

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = 

; XAMPP IMPORTANT NOTE (1): If XAMPP is installed in a base directory with spaces (e.g. 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 (e.g. 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=on

2)使sendmail.ini smtp部分看起来像这样

smtp_server=localhost

; smtp port (normally 25)

smtp_port=25

; 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

; if your smtp server requires authentication, modify the following two lines

<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a4c5d1d0ccfbd1d7c1d6cac5c9c199d1d7c1d6e4c3c9c5cdc88ac7cbc9" rel="noreferrer noopener nofollow">[email protected]</a>
auth_password=password

3) 下载 Stunnel https://www.stunnel.org/downloads.html并在 stunnel.conf 中进行以下更改。 Stunnel 正在托盘中运行,每次进行更改时,右键单击 Stunnel 图标并重新加载 conf 文件。

cert = stunnel.pem
socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1
key = stunnel.pem
[ssmtp]
accept  = 465
connect = 25
[gmail-smtp]
client = yes
accept = 127.0.0.1:25
connect = smtp.gmail.com:465
; To check logs you can enable logging using following lines
debug = 7

4 ) 转到 Sendmail 文件夹,右键单击 sendmail.exe -> 属性 -> 兼容性 -> 单击“为所有用户进行更改”按钮 -> 选择 Windows XP (Service Pack 3) 兼容性并勾选以管理员身份运行。

5 ) 始终以管理员身份启动 XAMPP!!

这仅在 Windows 8+ 上需要(例如,在 Windows 2008 R2 上,我只需要正确地将 sendmail 瞄准 gmail,一切正常)。

关于PHP Sendmail 在 Windows xampp 中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28532476/

相关文章:

php - 如何使用 YQL 获得超过 10 个查询结果?

php - 如何将 drupal 事件日历与 Outlook 日历同步

php - 如何在 PHP 中正确分离和删除 2 个进程之间的共享内存?

mysql - 无法在 MacOS 上运行 MySQL

ruby-on-rails - 从 Rails 控制台发送电子邮件

php - 从 PHP 脚本发送电子邮件的最佳方式是什么? [2]

php/mysql 从星期三开始一周中的一天,从星期二开始一周中的最后一天

web - 通过 Internet 从外部访问 Xampp

php - Windows、XAMPP、PHP 7 和 opcache

php - php 不发送邮件