我正在尝试使用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))
产生相同的结果