【问题标题】:How to get php mail() to work?如何让 php mail() 工作?
【发布时间】:2013-08-05 23:05:35
【问题描述】:

我的脚本.php

<?php
ini_set('display_errors', 1); 
error_reporting(E_ALL);

$to      = 'myemail@gmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: anotheremail@domain.com' . "\r\n" .
    'Reply-To: anotheremail@domain.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

$res = mail($to, $subject, $message, $headers);
var_dump($res);
?>

php.ini 要点

sendmail_path = /usr/sbin/sendmail -t -i
mail.log = /home/myuser/phpmail.log
  • 当我运行 script.php 时,大约需要 30 秒才会显示 bool(true)。
  • /home/myuser/phpmail.log 包含带有所有标题的条目
  • /usr/sbin/sendmail 是 sendmail 的正确路径
  • 电子邮件未通过。测试了几个不同的地址,例如邮寄者

如何让它工作?我可以做些什么来调试?

【问题讨论】:

  • 您的服务器是domain.com 的可信发件人吗?
  • 我首先要检查的是邮件服务器日志
  • 你检查过sendmail日志吗?
  • @Jack 取决于您对受信任的发件人的意思? Barmar:是的,恐怕没什么奇怪的。如果我找对地方了? /var/log/mail.log
  • This answer 对相关问题可能感兴趣。希望对您有所帮助。

标签: php sendmail


【解决方案1】:

0) 检查 sendmail 日志文件

1) 以同一系统用户发送测试消息

#!/bin/sh
/usr/sbin/sendmail -v -t -i <<END
To: myemail@gmail.com
Subject: the subject
From: anotheremail@domain.com
Reply-To: anotheremail@domain.com

hello
END
echo SENDMAIL EXIT CODE: $?

【讨论】:

  • 发送邮件日志中没有错误。该脚本运行良好,没有错误,并且电子邮件已发送。为什么?
【解决方案2】:

终于成功了

在 iptables 中为 localhost 打开端口 25 并从 php.ini 中的 sendmail_path 中删除“i”

sendmail_path = /usr/sbin/sendmail -t

【讨论】:

    猜你喜欢
    • 2012-05-06
    • 1970-01-01
    • 1970-01-01
    • 2012-06-15
    • 1970-01-01
    • 2018-06-04
    • 2012-03-23
    • 2012-02-12
    • 1970-01-01
    相关资源
    最近更新 更多