【问题标题】:sending mail to gmail with an php script使用 php 脚本向 gmail 发送邮件
【发布时间】:2013-07-13 05:30:53
【问题描述】:

1.使用 XAMPP 和 localhost 我正在尝试从 php 脚本向 gmil 发送邮件。
2.在尝试对文件 php.ini 和 sendmail.ini 进行所有更改后,如帖子和其他资源中所示,我无法从以下 php 代码行接收邮件:

    <?php
    mail('satanower1@gmail.com','hello this is a test','From: satanower1@gmail.com');
    echo 'mail has been sent successfully.';
    ?>

我收到了 echo 声明,但我的收件箱中没有电子邮件。
我尝试对 sendmail.ini 进行更改
来自 xampp defoult 的文件:smtp_server=smtp.gmail.com smtp_port=465(我也尝试过其他端口,如 25 等)

我尝试对 php.ini 文件进行的更改: SMTP = smtp.gmail.com 和 smtp_port = 465

有什么帮助吗?

【问题讨论】:

  • 首先尝试这个简单的脚本:if(mail('your@emailaddress.com', 'Test Subject', "Test message")) echo "sent"; else echo "not sent"; 如果它不起作用,请检查您的错误日志。
  • 您是否配置了 smtp 身份验证,您是从附加到您帐户的电子邮件地址发送的。
  • 您的echo 语句每次都会被执行。添加一个if 检查回显消息 如果邮件发送成功。此外,正如@Suyesh 上面所说,检查错误日志以查看问题是明智的。
  • 嗨。感谢您的快速回放
  • 我已经尝试过您在 (1) 处建议的脚本并得到了已发送的回声

标签: php email xampp


【解决方案1】:

您需要在 GMAIL 中启用 SMTP 访问,还需要允许不安全的客户端:

https://www.google.com/settings/security/lesssecureappshttps://support.google.com/mail/answer/75726

发送邮件配置

[sendmail]
smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=auto
error_logfile=error.log
debug_logfile=debug.log
auth_username==*****@gmail.com
auth_password=*********
force_sender=*****@gmail.com

php 配置

[mail function]
SMTP=smtp.gmail.com
smtp_port=465
sendmail_from = *****@gmail.com
sendmail_path = "\"c:\xampp\sendmail\sendmail.exe\" -t"

【讨论】:

    猜你喜欢
    • 2015-01-30
    • 2014-04-17
    • 1970-01-01
    • 2013-12-22
    • 2018-11-14
    • 2018-11-16
    • 2015-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多