php mail() function on localhost

Shark picture Shark · Mar 17, 2011 · Viewed 67.2k times · Source

I have problem with php mail() function on localhost server. I can't test my email application on localhost when i'm trying to send emails with php function mail().

I'm getting this error 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 F:\wamp\www\product\ajax.php on line 64

I'm using WAMP server and if anyone knows solution please help me.

Answer

Treffynnon picture Treffynnon · Mar 17, 2011

You need to setup a mail server on your machine for the mail function to work. If you are on Windows (which I am guessing you are from your use of WAMP) you can setup a Pegasus mail server.

Other options include using a wrapper class such as SwiftMailer or PHPMailer and using them to connect to another SMTP server such as your GMail account. Even if you go the Pegasus mail server on your own localhost route then I would still recommend using one of the two classes I have mentioned above. They give you far more flexibility and are safer.

Connecting to either your ISPs SMTP server or GMail or whatever is the easiest route out of this one.