<p>I'm getting this problem:</p>

<pre><code>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 
</code></pre>

<p>from this script:</p>

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

if (mail($to, $subject, $body)){
    echo "mail sent";
}
else {
    echo "problem";
}
?&gt;
</code></pre>

<p>section from php.ini on the server:</p>

<pre><code>[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 =
</code></pre>

<p>(note that "server" and "domain" refer accurately to the actual server and domain name)</p>

<p>In IIS, SMTP is running. Under <code>"Access"</code> tab, <code>"Relay"</code> button, the Select which computers may relay through this virtual server is set to <code>checkbox "only the list below"</code> and on the list is <code>"127.0.0.1(xxx.xxx.xxx.xxx)" (x's representing actual server IP address).</code></p>

<p>Server is running <code>Windows Server 2003 Service Pack 2</code>, fully patched as of 5 PM Sept 1st 2008. I assume it is running <code>IIS7</code> (how to check?).</p>

<p>Any ideas?</p>

<p>In reponse to <a href="https://stackoverflow.com/users/2257/espo">Espo</a>: This machine is hosted at a datacenter. We do not want to use a gmail account (were doing it, want to move away from that). Windows server 2003 comes with its own SMTP server.</p>

<p>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.</p>

<p>Thanks to both Espo and Yaakov for helping me out.</p>

[{'answer_id': 38923, 'author': 'Espo', 'author_id': 2257, 'author_profile': 'https://Stackoverflow.com/users/2257', 'pm_score': 1, 'selected': False, 'text': '<p>You are using the wrong SMTP-server. If you you are only going to send emails to your gmail-account, have a look at my answer <a href="https://stackoverflow.com/questions/29988/how-to-send-email-from-a-program-without-using-a-preexisting-account#30001">here</a>.</p>\n\n<p>If you also need to send email to other accounts, ask you ISP for your SMTP-details.</p>\n\n<p>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. 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).</p>\n\n<p>If you still for some reason want to use you local SMTP server, the first thing would be to rule out the php-part. Try folowing <a href="http://support.microsoft.com/kb/153119" rel="nofollow noreferrer">KB153119</a> and then check you SMTPServer IISlog for errors.</p>\n\n<p>EDIT2:\nThat 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.</p>\n'}, {'answer_id': 38947, 'author': 'Christopher Mahan', 'author_id': 479, 'author_profile': 'https://Stackoverflow.com/users/479', 'pm_score': 0, 'selected': False, 'text': "<p>@Espo: I'll do that re KB153119. Thanks.</p>\n\n<p>About the mail server: I hear you. </p>\n\n<p>I'll update when I uncover more.</p>\n"}, {'answer_id': 38961, 'author': 'Christopher Mahan', 'author_id': 479, 'author_profile': 'https://Stackoverflow.com/users/479', 'pm_score': 0, 'selected': False, 'text': '<p>@Espo, the article in question relates to Exchange servers, not IIS7.0 SMTP server.</p>\n\n<p>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. 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.</p>\n'}, {'answer_id': 38978, 'author': 'Yaakov Ellis', 'author_id': 51, 'author_profile': 'https://Stackoverflow.com/users/51', 'pm_score': 3, 'selected': True, 'text': '<p>Try removing the IP restrictions for Relaying in the SMTP server, and opening it up to all relays. 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.</p>\n'}, {'answer_id': 431440, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>I had the same problem, php 5 on iis6, 2003 server. Php always failed when trying to use mail().\nI'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' .\nThe relay restrictions can be found in the Access tab in the smtp servers properties screens.\nOf 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.</p>\n\n<p>hope that helps.</p>\n"}]
['https://Stackoverflow.com/questions/38920', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/479/']