user1995927
user1995927

Reputation: 311

mail function is not working in localhost server

I am on my localhost server. I am using this code below, but I never received the email.

<?php
$to = "[email protected]";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "[email protected]";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

Upvotes: 7

Views: 30927

Answers (2)

Johannes Mittendorfer
Johannes Mittendorfer

Reputation: 1252

Make sure that the mailserver is configured correctly in the php.ini file.

comment out these lines like this in php.ini file and restart the Apache server.

/*[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
; SMTP = localhost
; smtp_port = 25
*/

/*; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = postmaster@localhost
*/

Upvotes: 3

Suman
Suman

Reputation: 134

I know its kinda late...

check if your localhost is configured to send email

On ubuntu terminal try executing following command

# apt-get install sendmail

Upvotes: 5

Related Questions