使用GMAIL邮件服务器从PHP运行XAMMP的localhost发送电子邮件

ani*_*ani 22 php email gmail sendmail.exe

我尝试使用php mail()函数从localhost发送电子邮件到我的雅虎电子邮件帐户,返回说我成功发送了电子邮件,但我没有收到任何电子邮件.我一直在阅读并尝试许多所谓的"简单方式"来发送电子邮件,但结果令人失望,它们都不适合我.以下是代码,配置和错误消息.有人可以用这个启发我吗?谢谢.

PHP代码

<?php
$to      = 'myemail@yahoo.com';
$subject = 'Fake sendmail test';
$message = 'If we can read this, it means that our fake Sendmail setup works!';
$headers = 'From: myemail@egmail.com' . "\r\n" .
           'Reply-To: myemail@gmail.com' . "\r\n" .
           'X-Mailer: PHP/' . phpversion();

if(mail($to, $subject, $message, $headers)) {
    echo 'Email sent successfully!';
} else {
    die('Failure: Email was not sent!');
}
?>
Run Code Online (Sandbox Code Playgroud)

配置php.ini(我正在使用gmail邮件服务器)

SMTP = smtp.gmail.com
smtp_port = 587
sendmail_from = myemail@gmail.com
sendmail_path ="\"C:\ xampp\sendmail\sendmail.exe \" - t"

sendmail.ini的配置

smtp_server = smtp.gmail.com
smtp_port = 587
smtp_ssl = tls
error_logfile = error.log
debug_logfile = debug.log
auth_username=myemail@gmail.com
auth_password = mypassword
force_sender=myemail@gmail.com

sendmail错误日志中的错误消息,端口为587

13/10/02 13:36:41:必须先发出STARTTLS命令.k4sm129639pbd.11 - gsmtp

ani*_*ani 20

是给我答案的链接:

[安装]" 假的sendmail for Windows ".如果您不使用XAMPP,可以在此处下载:http://glob.com.au/sendmail/sendmail.zip

[Modify] the php.ini file to use it (commented out the other lines):

[mail function]
; For Win32 only.
; SMTP = smtp.gmail.com
; smtp_port = 25

; For Win32 only.
; sendmail_from = <e-mail username>@gmail.com

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = "C:\xampp\sendmail\sendmail.exe -t"
Run Code Online (Sandbox Code Playgroud)

(忽略"仅限Unix"位,因为我们实际上使用的是sendmail)

然后,您必须在安装sendmail的目录中配置"sendmail.ini"文件:

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=<username>
auth_password=<password>
force_sender=<e-mail username>@gmail.com
Run Code Online (Sandbox Code Playgroud)

要访问受双因素验证保护的Gmail帐户,您需要创建特定应用程序的密码.(来源)

  • 我认为gmail现在需要ssl (3认同)