0

这是我的配置文件。

发送邮件.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…";
}
?>

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

4

2 回答 2

1

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

于 2012-04-12T04:19:20.273 回答
0

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

于 2013-06-30T22:41:34.067 回答