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      = "[email protected]";
$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
https://forums.phpfreaks.com/topic/223051-mail-function-not-working/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.