我整个早上都在互联网上搜索这个,试图找到一个解决方案。我已经在 Windows 8.1 上安装了 wamp 服务器,我正在尝试使用 sendmail ( http://glob.com.au/sendmail/ ) 和我的 gmail 帐户发送一些邮件
当我将 sendmail 配置为使用端口号 465 时,我总是收到此错误:Socket Error # 10060Connection timed out
如果我尝试使用端口号 587,我会在错误日志中看到这一行:连接正常关闭。但没有发送电子邮件。
这是我的 sendmail.ini 文件
[sendmail]
smtp_server=smtp.gmail.com
;I tried both: 587, 465
smtp_port=587
; I tried: "blank, auto ssl, tls, none"
smtp_ssl=
error_logfile=error.log
debug_logfile=debug.log
auth_username=myaccoun@gmail.com
auth_password=mypass
hostname=localhost
这是 php.ini 文件
[mail function]
smtp_port = 465
sendmail_path="C:\wamp\sendmail\sendmail.exe -t"
mail.add_x_header = On
ssl_module 在 apache 上处于活动状态,php 使用 php_open_ssl 和 php_socket 扩展。
我也尝试使用 stunnel 没有任何成功
编辑 27/01/2014
我在 sendmail.ini 上设置了 smtp_port = 465 和 smtp_ssl=ssl。另外,我设置 sendmail.exe 必须作为 Windows XP SP3 程序运行。之后,当我在 Windows 控制台上运行 sendmail.exe 时,它会正确发送电子邮件。但是,当 wamp 尝试发送邮件时,我在 sendmail 的错误日志中收到此错误。:Socket Error # 10060Connection timed out。
这是我用来测试 sendmail 的代码:
<?php
$email = "mymail@gmail.com";
$to = "mymail@gmail.com";
$subject = "Hi!";
$body = "Hi,How are you?";
$headers = 'From: ' .$email . "\r\n".'Reply-To: ' . $email. "\r\n".'X-Mailer: PHP/' . phpversion();
if (mail($to, $subject, $body, $headers)) echo("<p>Email successfully sent</p>");
else echo("<p>Email delivery failed</p>");
?>