Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a Windows Webserver 2008 running with PHP installed. PHP works fine, except when I try to use the mail() function in oder to programmatically send emails via PHP. Then I get this error:

Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in ...

So, what do I have to install to confire in order to send emails via my PHP script?

I dont know much about mail configuration, but I have the bad feeling of being in for torture...

share|improve this question
add comment

2 Answers

As an alternative, which is Windows-only, you can configure PHP to use a remote SMTP server for sending mail. This bypasses the need to configure IIS SMTP if all you'd have it doing is forwarding to a smarthost anyway.

In php.ini:

SMTP=smtp-server.example.com

See the PHP mail configuration reference at php.net for other stuff you can do in the INI file.

share|improve this answer
    
@max - Walters got it right, Sending it from a properly configured mail server also lowers the chance of your message ending up in your customers spam folder. –  txyoji Oct 27 '09 at 13:44
    
I know about this option, but what am I to do if I dont have any external smtp server at hand? –  Max Oct 27 '09 at 14:44
    
If you don't, then you will indeed have to configure an SMTP server, whether locally on the server or somewhere else on the network. Note that this means properly securing it, making sure it passes SPF record checks if applicable for your domain, etc. It's better to use an existing server if there is one, naturally. However, if not, the "...if all you'd have it doing is forwarding to a smarthost anyway" proviso on my answer doesn't apply and you have to do it the hard way. –  Walter Mundt Oct 27 '09 at 15:06
    
Thanks for the hint! I think if I had another SMTP server, I would use it. However, there is only one customer on the server and this one will receive the emails. So spam should not be a problem. Any more information on how to secure the SMTP server? –  Max Oct 27 '09 at 15:55
1  
Note, after making changes in php.ini you need to may need to 'iisreset' for them to take effect... at least that is what made mine work just now. –  Nathan Jun 25 '10 at 0:41
show 1 more comment
up vote 1 down vote accepted

Allright, got it, not too hard after all.

Install SMTP following this guide: http://www.jppinto.com/index.php/2009/02/installing-iis-70-with-smtp-on-windows-server-2008/ (scroll down, it starts with installing IIS 7, the second part is about SMTP).

Check that the "Simple Mail Transfer Protocol (SMTP)" Service is up and running.

EDIT: Go to IIS 7 Manager, go to the website you need SMTP. Go to SMTP settings, be sure to check the "localhost" checkbox and save.

Go to start, administrative tools, internet info services(iis) 6.0.

Check that the SMTP server is up and running.

Right click on the SMTP server, select properties.

Go to the "Access" tab.

There is an option where you can define which hosts are allowed to connect to the SMTP server. Add "127.0.0.1" to the list of allowed hosts.

EDIT 2: There is also an option where you define the hosts to send to. If you e. g. have an IP (range) of the host(s) which should receive your emails, enter it here. Else choose "all except" and do not add any IP addresses.

Then you're good to go.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.