电子邮件已发送!但未在收件箱中收到.PHP -> localhost -> XAMPP -> Web Server


Email sent! But not received on inbox. PHP -> localhost -> XAMPP -> Web Server

这是我的配置文件。

发送邮件.ini

[sendmail]
; you must change mail.mydomain.com to your smtp server,
; or to IIS's "pickup" directory.  (generally C:'Inetpub'mailroot'Pickup)
; emails delivered via IIS's pickup directory cause sendmail to
; run quicker, but you won't get error messages back to the calling
; application.
smtp_server=(Correct SMTP Server)
; smtp port (normally 25)
smtp_port=25

PHP.ini

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = (Correct SMTP Server)
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = (user@(server.com)) <- correct name

PHP代码

<?php
$from_name = "testing";
$from_email = "myemail@something.com";
$headers = "From: $from_name <$from_email>";
$headers = "MIME-Version: 1.0" . "'r'n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "'r'n";
$body = "Hi,'nThis is a test mail from $from_name <$from_email>.";
$subject = "Test mail from test";
$to = "myemail@something.com";
if (mail($to, $subject, $body, $headers)) {
  echo "success!";
} else {
  echo "fail…";
}
?>
当我

运行代码时,它确实说电子邮件已发送,但是当我检查电子邮件时,没有任何内容可接收......请帮忙!谢谢,我将提供尽可能多的相关信息来解决此问题。

如果您在家中或小型办公室进行测试,那么您的 ISP 可能会阻止端口 25 上的出站流量。你的PHP不会失败,但你的消息会被阻止。您需要连接到另一个端口(如 465 或 587)上的外部 SMTP 服务器。请查阅您的 ISP 网站,了解有关其允许的内容的详细信息。

如果你仔细观察,你会发现你的第二个$header变量上缺少一个串联,因此,你没有发送"From:"标头,这可能会导致邮件被拒绝。