Question

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:

[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. 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).

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?).

Any ideas?

In reponse to Espo: 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.

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.

Thanks to both Espo and Yaakov for helping me out.

Was it helpful?

Solution

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.

OTHER TIPS

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 here.

If you also need to send email to other accounts, ask you ISP for your SMTP-details.

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).

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 KB153119 and then check you SMTPServer IISlog for errors.

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.

@Espo: I'll do that re 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.

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.

I had the same problem, php 5 on iis6, 2003 server. Php always failed when trying to use mail(). 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' . The relay restrictions can be found in the Access tab in the smtp servers properties screens. 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.

hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top