简体   繁体   English

php mail()无法在Windows 2003,IIS SMTP中运行

[英]php mail() not working windows 2003, IIS SMTP

I'm getting this problem: 我遇到了这个问题:

PHP Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable to relay for chris.mahan@gmail.com in c:\inetpub\wwwroot\mailtest.php on line 12 

from this script: 从这个脚本:

<?php
$to = "chris.mahan@gmail.com";
$subject = "test";
$body = "this is a test";

if (mail($to, $subject, $body)){
    echo "mail sent";
}
else {
    echo "problem";
}
?>

section from php.ini on the server: 服务器上php.ini中的部分:

[mail function]
; For Win32 only.
SMTP = server.domain.com; for Win32 only
smtp_port = 25

; For Win32 only.
sendmail_from = support@domain.com
; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =

(note that "server" and "domain" refer accurately to the actual server and domain name) (请注意,“服务器”和“域”准确指代实际的服务器和域名)

In IIS, SMTP is running. 在IIS中,SMTP正在运行。 Under "Access" tab, "Relay" button, the Select which computers may relay through this virtual server is set to checkbox "only the list below" and on the list is "127.0.0.1(xxx.xxx.xxx.xxx)" (x's representing actual server IP address). "Access"选项卡的"Relay"按钮下,选择"Relay"可以通过此虚拟服务器中继的计算机checkbox "only the list below"checkbox "only the list below"并且列表上的名称为"127.0.0.1(xxx.xxx.xxx.xxx)" (x's representing actual server IP address).

Server is running Windows Server 2003 Service Pack 2 , fully patched as of 5 PM Sept 1st 2008. I assume it is running IIS7 (how to check?). 服务器正在运行Windows Server 2003 Service Pack 2 ,该补丁已于2008年9月1日下午5点进行了全面修补。我认为服务器正在运行IIS7 (如何检查?)。

Any ideas? 有任何想法吗?

In reponse to Espo : This machine is hosted at a datacenter. 作为对Espo的响应:该计算机托管在数据中心。 We do not want to use a gmail account (were doing it, want to move away from that). 我们不想使用gmail帐户(正在这样做,希望不再使用该帐户)。 Windows server 2003 comes with its own SMTP server. Windows Server 2003带有自己的SMTP服务器。

Update: Per Yaakov Ellis' advice, I dropped all relay restrictions and added the server IP to the allowed list (using the reverse DNS button provided) and the thing started working. 更新:根据Yaakov Ellis的建议,我放弃了所有中继限制,并将服务器IP添加到允许的列表中(使用提供的反向DNS按钮),事情开始起作用。

Thanks to both Espo and Yaakov for helping me out. 感谢Espo和Yaakov的帮助。

Try removing the IP restrictions for Relaying in the SMTP server, and opening it up to all relays. 尝试删除SMTP服务器中中继的IP限制,然后将其开放给所有中继。 If it works when this is set, then you know that the problem has to do with the original restrictions. 如果在设置该选项后可以正常工作,则您知道问题与原始限制有关。 In this case, it may be a DNS issue, or perhaps you had the wrong IP address listed. 在这种情况下,可能是DNS问题,或者您列出的IP地址错误。

You are using the wrong SMTP-server. 您使用了错误的SMTP服务器。 If you you are only going to send emails to your gmail-account, have a look at my answer here . 如果您只打算将电子邮件发送到您的gmail帐户,请在此处查看我的答案。

If you also need to send email to other accounts, ask you ISP for your SMTP-details. 如果您还需要向其他帐户发送电子邮件,请向ISP询问您的SMTP详细信息。

EDIT: I think it is always better to use the ISP SMTP-server as they (should) have people monitoring the mail-queues, checking for exploits and updating the mail-software. 编辑:我认为使用ISP SMTP服务器总是更好,因为(应该)让人们监视邮件队列,检查漏洞并更新邮件软件。 If you business is developing web-applications it is almost always best to stick with what you do, and let other people do their stuff (eg running mailservers). 如果您的企业正在开发Web应用程序,则几乎总是最好坚持自己所做的事情,并让其他人做自己的事情(例如,运行邮件服务器)。

If you still for some reason want to use you local SMTP server, the first thing would be to rule out the php-part. 如果您仍然出于某种原因想要使用本地SMTP服务器,那么第一件事就是排除php部分。 Try folowing KB153119 and then check you SMTPServer IISlog for errors. 尝试遵循KB153119 ,然后检查SMTPServer IISlog中的错误。

EDIT2: That KB-article says it is for exchange, but the same commands are used for other SMTP-servers (including IIS) as well, so please try and see if you can send mails using the examples from the article. EDIT2:该知识库文章说它是用于交换的,但是相同的命令也用于其他SMTP服务器(包括IIS),因此请尝试使用本文中的示例查看是否可以发送邮件。

@Espo: I'll do that re KB153119. @Espo:我会做KB153119。 Thanks. 谢谢。

About the mail server: I hear you. 关于邮件服务器:我听到了。

I'll update when I uncover more. 我会在发现更多内容时进行更新。

@Espo, the article in question relates to Exchange servers, not IIS7.0 SMTP server. @Espo,有问题的文章与Exchange服务器有关,而不与IIS7.0 SMTP服务器有关。

From the summary: This article describes how to telnet to port 25 on a computer that runs Simple Mail Transfer Protocol (SMTP) services to troubleshoot SMTP communication problems. 摘自:本文介绍如何通过telnet到运行简单邮件传输协议(SMTP)服务的计算机上的端口25来解决SMTP通信问题。 The information in this article, including error messages, only applies to issues when attempting to resolve SMTP communication issues with Microsoft Exchange-based servers and is not intended for general troubleshooting purposes. 本文中的信息(包括错误消息)仅适用于尝试解决与基于Microsoft Exchange的服务器的SMTP通信问题时的问题,并不用于一般的故障排除目的。

I had the same problem, php 5 on iis6, 2003 server. 我有同样的问题,iis6,2003服务器上的php 5。 Php always failed when trying to use mail(). 尝试使用mail()时,php总是失败。 I've managed to get it accepting mail from php by changing the Relay Restrictions from 'Only the list below' (which is empty by default) to 'All except the list below' . 通过将“中继限制”从“仅以下列表”(默认情况下为空)更改为“除以下列表之外的所有内容”,我设法使其接受了来自php的邮件。 The relay restrictions can be found in the Access tab in the smtp servers properties screens. 可以在smtp服务器属性屏幕的“访问”选项卡中找到中继限制。 Of course if the server is open to the internet then one would have to be more sensible about these relaying restrictions but in my case this is on a virtual server on a dev box. 当然,如果服务器对Internet开放,那么必须对这些中继限制更加敏感,但是在我的情况下,这是在开发箱上的虚拟服务器上。

hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM