当$ to field来自mysqli对象时,php mail()函数失败。 cpanel服务器

时间:2013-06-08 15:25:47

标签: php mysqli

我正在尝试使用PHP中的$mysqli->query函数将消息通过电子邮件发送到我使用mail()从数据库查询的地址。 mail()函数返回true,但我没有收到任何电子邮件。这是我的代码的一部分:

    if($result = $mysqli->query($query)){
        $obj = $result->fetch_object();
        $to = $obj->email;
    }

    mail($to, $subject, $message, $headers);

我确定其他参数($subject, $message, $headers)设置得很好,因为我可以通过将行$to = $obj->email;替换为$to = 'myemail@gmail.com';

我也尝试了strcmp($to, 'myemail@gmail.com'),它返回零。意思是字符串没有区别。

更新

正如有人建议的那样,我试着查看日志。以下是它的一些部分:

 Delay reason: SMTP error from remote mail server after initial connection:
host mx-apac.mail.gm0.yahoodns.net [106.10.166.52]:
421 4.7.1 [TS03] All messages from 64.120.250.230 will be permanently deferred; Retrying will NOT succeed. See http://postmaster.yahoo.com/421-ts03.html

No action is required on your part. Delivery attempts will continue for
some time, and this warning may be repeated at intervals if the message
remains undelivered. Eventually the mail delivery software will give up,
and when that happens, the message will be returned to you.

在另一个日志中,这就是它所说的:

A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:
xxxxxxx@yahoo.com
retry time not reached for any host after a long failure period

现在,当我在to功能的mail参数中对电子邮件进行硬编码时,我仍然不知道为什么电子邮件会发送得很好。

此外,代码var_dump($to)var_dump(trim($to))会产生相同的结果

1 个答案:

答案 0 :(得分:2)

你甚至打扰阅读日志吗?

它告诉你它为什么没有交付,甚至你可以获得更多信息。

相关问题