Jump to content

Mail function not working


Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.