RLJ Posted December 31, 2010 Share Posted December 31, 2010 Hi, I installed WAMP to install & configure PHP & MySQL, etc. automatically and am really impressed, everything so far has worked "straight out the box", except for the PHP mail function. I use the following PHP code to send an email: <?php $to = "LRLJ@hotmail.co.uk"; $subject = " YOURWEBSITE.com Registration"; $message = "TEST MESSAGE"; $headers = 'From: noreply@ YOURWEBSITE.com' . "\r\n" . 'Reply-To: noreply@ YOURWEBSITE.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); ?> Which gives me the following error message: Warning: mail() [function.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 C:\wamp\www\mail.php on line 9 Pls help! How do I configure php.ini so the mail function works? Or could it be something to do with my firewall? Many thanks! Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 31, 2010 Share Posted December 31, 2010 You need a mail server in order to send an email. The php mail() function only provides a way for a php script to interface with a local mail server, either using SMTP or through the mail server's command line interface. Quote Link to comment Share on other sites More sharing options...
RLJ Posted December 31, 2010 Author Share Posted December 31, 2010 Cheers for the reply. Do you know an easy way to set up a mail server on my PC? I just want to test the mail function. Thanks. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 31, 2010 Share Posted December 31, 2010 To get a local mail server that will actually send an email to an external email address requires that you have a valid domain name (or use a hostname from a service like DynDNS) and a DNS server (from a service like DynDNS) where you can put all the necessary dns zone records to make your mail server a valid public mail server that other mail servers will accept an email from. You would also need to determine if your ISP hasn't blocked the ports necessary to do this and you will need to configure your router/firewall. You can also just set up a local mail server that will accept an email from the php mail() but send it only to a local dummy mail box on the local mail server. There are a number of free/open source mail servers and you can probably find one that is ported to work on your operating system. Do you need to test your mail function by actually sending an email? Couldn't you just log the $to, $subject, $message, and $headers variables to make sure of what they contain? You can also use a php class, such as phpmailer with SMTP Authentication to use a remote mail server, such as your ISP's mail server or a gmail/hotmail account you may already have. Quote Link to comment Share on other sites More sharing options...
RLJ Posted January 1, 2011 Author Share Posted January 1, 2011 Ah I see. Sounds like a lot of effort then! I think I'll just assume for the moment the mail function will work and log $to, $subject, $message, and $headers variables as you say. Thanks for your help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.