November 4th, 2012, 12:37 PM
Apache and php mail; function
I'm using the php mail function to send an email containing a submitted forms fields. I'm using the following code:
I'm not getting any of the emails, however the "Your message was sent" Text is showing, which is in a conditional that checks if the form was successfully submitted, so I know that's not it.
$to = "firstname.lastname@example.org";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "email@example.com";
$headers = "From:" . $from;
echo 'Thank you. Your message was sent.';
I am testing and using this web application on my localhost using Apache server, I'm thinking maybe apache is the problem? Could it be, or do I have code wrong?
November 4th, 2012, 12:55 PM
it is not possible you to send this email from localhost.because The Email server is need it to set to localhost.
November 4th, 2012, 07:29 PM
I don't know what maximas is trying to say, but
You need to check the return value from mail(). It could return false indicating that it couldn't send the mail - probably due to a configuration problem.
If that's not it then try to use a more sophisticated mailing library, like PHPMailer. It can handle problems that you didn't even know you were facing.