当前位置: 首页 > 面试题库 >

使用GMAIL邮件服务器从在PHP中运行XAMMP的本地主机发送电子邮件

璩正志
2023-03-14
问题内容

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

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!');
}
?>

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


问题答案:

这是给我答案的链接:

[安装]“ 用于Windows的伪sendmail
”。如果您不使用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”

(忽略“仅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


 类似资料:
  • sendmail.ini的配置 smtp_server=smtp.gmail.com smtp_port=587 smtp_ssl=tls error_logfile=err.log debug_logfile=debug.log auth_username=myemail@gmail.com auth_password=mypassword force_sender=myemail@gmail.

  • 问题内容: 我正在Windows上使用WampServer来测试站点。我有一个注册系统,用户会收到一封确认电子邮件。 是否可以从本地主机发送电子邮件? 问题答案: 如果要直接从本地主机发送电子邮件,则需要安装邮件传输代理(MTA),或者安装SMTP服务。 IIS提供了一个。否则,您可以在Google上找到其他人。 您也可以更改 邮件设置。这将不使用每条说来发送电子邮件,而是用于允许您从PHP脚本发

  • 我无法发送电子邮件从本地主机使用php脚本这是我的代码 ?> php.ini文件... “邮件功能” ;仅适用于Win32。 请帮助我解决我的问题。

  • 问题内容: 我正在尝试从PHP页面通过GMail的SMTP服务器发送电子邮件,但出现此错误: 身份验证失败[SMTP:SMTP服务器不支持身份验证(代码:250,响应:mx.google.com,为您提供服务,[98.117.99.235]大小为35651584 8位MIME STARTTLS增强的状态代码,编码方式)]] 有人可以帮忙吗?这是我的代码: 问题答案: // Pear Mail Li

  • 我试图发送电子邮件使用gmail smtp使用javax.mail.下面是我的代码 代码工作正常当我在本地服务器上运行它时,但当我尝试在Elastic beanstek上运行它时(我的服务器在AWS EBS上运行),身份验证失败异常即将到来注意:我已打开从Google A/c设置访问不太安全的应用程序,但我仍然收到此错误 javax.mail.身份验证失败异常:534-5.7.14请通过您的网络浏

  • 问题内容: 我在寻找有关如何 从localhost WAMP发送电子邮件的 适当信息。以及如何获得从特定的授权电子邮件地址发送电子邮件的授权以发送任何其他电子邮件地址。 如何配置这整个步骤向我解释了细节,我已经在这里访问了一些Stack Overflow的答案以及博客文章,但是所有内容都很混乱且过时,因此可能无法正常工作。所以我需要Stack Overflow用户帮助。谢谢。 问题答案: 从配置工