【问题标题】:Localhost Sendmail does not work本地主机发送邮件不起作用
【发布时间】:2014-08-19 23:06:05
【问题描述】:

我是 PHP 的初学者,我正在尝试从本地主机发送邮件,但它不起作用。一直在寻找一些解决方案,但似乎没有任何帮助。有人请指教。

这是我的 sendmail.ini 文件(保存在 C:\xampp\sendmail\sendmail.exe 中)

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=my-id@gmail.com
auth_password=my-password
force_sender=my-id@gmail.com

这是我的 php.ini 在 SMTP 部分的一小部分:

[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = my-id.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

这是我的 PHP 文件:

<?php 
$to = "test@gmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

if (mail($to, $subject, $body)) {
    echo("<p>Message successfully sent!</p>");
} else {
    echo("<p>Message delivery failed...</p>");
}
?>

我总是收到“无论我尝试什么,消息传递都失败。请帮助

【问题讨论】:

  • 您尝试添加标题了吗?
  • 嗨,你好。我试过了,没有任何改变

标签: php email web smtp sendmail.exe


【解决方案1】:

请务必注释掉您未在 php.ini 中使用的邮件功能:

[mail function]
;SMTP = localhost
;smtp_port = 25
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
;sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"

仅当您运行自己的 smtp 服务器时才需要 SMTP 和 smtp_port。第二个 sendmail_path 运行一个程序,将所有邮件写入邮件输出文件夹。

【讨论】:

    猜你喜欢
    • 2014-05-17
    • 1970-01-01
    • 2016-11-19
    • 2013-02-26
    • 2013-10-01
    • 2013-08-19
    • 2010-12-19
    • 2021-02-12
    • 1970-01-01
    相关资源
    最近更新 更多