PHP Contact Form not sending email

Hey guys. So I have a very simple contact form that wont send emails. Here is the link:

Upon clicking “Send”, the page displays “Your message has been sent successfully!”, but no email is ever received. I’ve changed the email address in the php multiple times but nothing.

Here is the code:

<?php $receiverMail = "[email protected]"; /* Your email */ $name = ltrim(rtrim(strip_tags(stripslashes($_POST['name'])))); $email = ltrim(rtrim(strip_tags(stripslashes($_POST['email'])))); $website = ltrim(rtrim(strip_tags(stripslashes($_POST['website'])))); $msg = ltrim(rtrim(strip_tags($_POST['msg']))); $subject = $name ." - ".$website; $ip = getenv("REMOTE_ADDR"); $msgformat = "From: $name ($ip)\nEmail: $email\n\n$msg"; /* MSG format */ // VALIDATION if(empty($name) || empty($email) || empty($website) || empty($msg)) { echo "
The email was not sent. Please fill all the required fields
"; } elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { echo "
The email was not sent. The email address is invalid
"; } else { mail($receiverMail, $subject, $msgformat, "From: $name <$email>"); echo "
Your message has been sent successfully!


except for ereg being depreciated, i don’t see anything wrong with the code. I would suggest putting some headers in there though, most servers now require more than just from, otherwise it could get caught up in the spam traps. If you haven’t done so, look in your junk folder.

Probably something with your sendmail configuration. If you can’t fix that then you could try using phpmailer that allows you to use smtp servers.

Btw. What’s the point of ltrim(rtrim(something))? why not just trim(something) ?

Trim takes it off the front, ltrim takes it off the back. Its not needed thpugh since its done automatically when its inserted

Sponsor our Newsletter | Privacy Policy | Terms of Service