邮件已发送!但收件箱中未收到。 PHP - > localhost - > XAMPP - >网络服务器

时间:2012-04-12 03:55:20

标签: php email outlook xampp localhost

以下是我的配置文件。

sendmail.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…";
}
?>

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

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

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