PHP$mysqli->query
の関数を使用して、データベースから照会したアドレスにメッセージを電子メールで送信しようとしています。関数は true を返しますが、メールが届きませんmail()
。mail()
ここに私のコードの一部があります:
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))
同じ結果が得られます