Mail() in php not working

this is my whole code, and I only get to the else statement that the email was not sent, any suggestions?

<?php $emailTo = "lisa@theultimatefanblog.com"; $subject = "Email this should work"; $body = "This is my message"; $headers = "From: joey@davallinc.com"; if (mail($emailTo, $subject, $body, $headers)) { echo "The email was sent successfully"; } else { echo "The EMAIL could not be sent."; } ?>

Hey, I am not really experienced in PHP, but your code seems to be correct. Where are you running this code on? If you are using XAMPP or something like that, the mail function is most likely not available.

I did find what went wrong. I had created a php.ini file to turn on error reporting so I could see what errors I was producing while php coding. That was the only thing I had changed on the server. Tech support for the server said everything looked good and comparing my code against different php help sites. I saw several references to the .ini file and since I added the file to my folder I thought maybe my file was interfering with the server php.ini file. So I deleted that file and ran my code, and I had success.

Here’s what you could use for your send_email.php

<?php session_start(); if(isset($_POST['submit'])) { $to = "you@somedomain.com"; // this is your Email address $from = $_POST['email']; // this is the sender's Email address $first_name = $_POST['full_name']; $email = $_POST['email']; $telephone = $_POST['telephone']; $comments = $_POST['message']; $subject = "Contact Form"; $message = "First Name: " . $first_name . "\n\n" . "Email: " . $email . "\n\n" . "Phone: " . $telephone . "\n\n" . "Message: " . $_POST['message']; mail($to, $subject, $message); header('Location: contact.php'); } ?>

the “header(‘Location: contact.php’);” will ensure that once the form is submitted, it won’t go to another page but stay on that same page. If you want it to go to another page, in the code above it would be the page “send_email.php”, then delete the header line. This header line is NOT to be confused with $headers or $header that would say it’s from john@gmail.com or whatever.