使用 GMAIL 邮件服务器从在 PHP 中运行 XAMMP 的本地主机发送电子邮件 [英] Send email from localhost running XAMMP in PHP using GMAIL mail server

查看:34
本文介绍了使用 GMAIL 邮件服务器从在 PHP 中运行 XAMMP 的本地主机发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I try to send an email from localhost to my yahoo email account using php mail() function, the return says I successfully send the email but I did not get any email. I've been reading and trying many so called 'simple way' to send email but the result are disappointing, none of them work for me. Below are the code, the configurations and the error message. Can someone enlighten me with this? Thanks.

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' . "
" .
           'Reply-To: myemail@gmail.com' . "
" .
           'X-Mailer: PHP/' . phpversion();

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

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

Configuration for php.ini (I'm using gmail mail server)

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

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

sendmail.ini 的配置

Configuration for 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=我的密码
force_sender=myemail@gmail.com

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

使用端口 587 的 sendmail 错误日志中的错误消息

error message in sendmail error log with port 587

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

13/10/02 13:36:41 : Must issue a STARTTLS command first. k4sm129639pbd.11 - gsmtp

推荐答案

这是给我答案的链接:

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

[Install] the "fake sendmail for windows". If you are not using XAMPP you can download it here: 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:xamppsendmailsendmail.exe -t"

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

(ignore the "Unix only" bit, since we actually are using sendmail)

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

You then have to configure the "sendmail.ini" file in the directory where sendmail was installed:

[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

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

To access a Gmail account protected by 2-factor verification, you will need to create an application-specific password. (source)

这篇关于使用 GMAIL 邮件服务器从在 PHP 中运行 XAMMP 的本地主机发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆