Contact Form submits but i don't receive any emails

Hi there

My Contact Form submits everything and tells me that it has been submitted but if i go to my mail box i do not receive any email from my contact form please can someone just help me I cant seem to get the problem .

Here is my Bootstrap form code:

<form class="form-horizontal" role="form" method="post" action="send_form_email.php">
    
         <div class="form-group">
                            <label class="control-label col-md-2" for="full_name">Your Full Name:</label>
                            <div class="col-md-10">
                                <input required="required" type="text" class="form-control" id="full_name" name="full_name" placeholder="Full Name" />
                            </div>
                        </div>
                        
                         <div class="form-group">
                            <label class="control-label col-md-2" for="telephone" >Your Telephone</label>
                            <div class="col-md-10">
                                <input required="required" type="text" class="form-control" id="telephone" name="telephone" placeholder="Your Telephone" />
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <label class="control-label col-md-2" for="email">Your Email:</label>
                            <div class="col-md-10">
                                <input required="required" type="email" class="form-control" id="email" name="email" placeholder="Your Email" />
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <label class="control-label col-md-2" for="message">Your Message:</label>
                            <div class="col-md-10">
                                <textarea required="required" rows="6" class="form-control" id="message" name="message" placeholder="Your Message"></textarea>
                            </div>
                           </div>
                           
                       

      <div class="modal-footer">
        <button type="button" class="btn btn-danger btn-lg" data-dismiss="modal">Close</button>
        <button class="btn btn-primary" type="submit">Send</button> 
      </div>
      </form>

and Here is my PHP Script:

i tried changing this if(isset($_POST[‘email’])) to if(isset($_POST[‘submit’])) but no success

<?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "info@momentdesigns.co.za"; $email_subject = "Your email subject line"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.

"; echo $error."

"; echo "Please go back and fix these errors.

"; die(); } // validation expected data exists if(!isset($_POST['full_name']) || !isset($_POST['telephone']) || !isset($_POST['email']) || !isset($_POST['message'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $full_name = $_POST['full_name']; // required $telephone = $_POST['telephone']; // required $email_from = $_POST['email']; // required $message = $_POST['message']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.
'; } $telephone_exp = '/^[0-9]*$/'; if(!preg_match($telephone_exp,$telephone_from)) { $error_message .= 'The Telephone number you entered does not appear to be valid.
'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$full_name)) { $error_message .= 'The Full Name you entered does not appear to be valid.
'; } if(strlen($message) < 2) { $error_message .= 'The Message you entered do not appear to be valid.
'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Full Name: ".clean_string($full_name)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Message: ".clean_string($message)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); sleep(2); echo ''; echo ""; ?>
 <?php
}
?>

Is it failing because you’re trying to use the form-fillers email address as the ‘from’ address? Surely it should be sent to you from your address, with users email address in the text? Your SMTP server might be checking that it’s not being used for open relay.

Ok so I have to change type=“email” to type=“text”?

Its not failing to submit the form it failing to send and receive it to my mailbox.

No, where you start to build up the headers, in the “From” section you’re using $email_from, which is the email address that the user entered into the form. You need to use your email address instead.

Need to change to this:

// create email headers
$headers = 'From: '.$email_to.“\r\n”.
'Reply-To: '.$email_to.“\r\n” .
‘X-Mailer: PHP/’ . phpversion();

Sorry but I am not the most clever with PHP

That might help, give it a go. If it doesn’t, have a look around some of the other email threads on here and see if any of them help, or perhaps someone else will comment. Also read up on enabling error messages, in case there’s something going wrong that PHP isn’t telling you about.

Ok well I tried it but no success thank you, I just hope someone can help

First - take the @ symbol from the start of your mail line, as that suppresses error messages. That might tell you what’s going wrong.

Second - add echo() statements through the code so you can see how far it’s getting. That will help you narrow down exactly which section of the code is failing.

I did all that, my code is clean there is no failing and i took away the @ symbol

Hi there Jonathan, he was trying to tell you to place echo statements throughout the script, so you could see how far it got. If you placed:

echo 1;

echo 2;

echo 3;

Then you could see where it’s making it to. If it makes it all the way to the last echo at the bottom of the page, then you know it completed the script and it didn’t stop somewhere in the middle.

That being said, I made some changes to the really terribad mail script you’re trying to use. From the email regex that would fail on many addresses to checking for the presence of a form field but not checking for it to be empty, it’s less than zoomy.

Here’s a cleaned up and slightly modified version of the mailer script:

[code]<?php

// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = “info@momentdesigns.co.za”;
$email_subject = “Your email subject line”;

$stop_reason = ‘’;

if(!ISSET($_POST[‘email’])) {
echo(“This page can only be accessed from the contact form. Sorry about that.
”);
exit;
}

// validation expected data exists
if((!ISSET($_POST[‘full_name’]) OR $_POST[‘full_name’] == ‘’) OR
(!ISSET($_POST[‘telephone’]) OR $_POST[‘telephone’] == ‘’) OR
(!ISSET($_POST[‘email’]) OR $_POST[‘email’] == ‘’) OR
(!ISSET($_POST[‘message’]) OR $_POST[‘full_name’] == ‘’)) {

echo("All of the form fields are required.<br />");
exit;

}

$full_name = $_POST[‘full_name’]; // required
$telephone = $_POST[‘telephone’]; // required
$email_from = $_POST[‘email’]; // required
$message = $_POST[‘message’]; // required

if(!filter_var($email_from, FILTER_VALIDATE_EMAIL)){
$stop = ‘1’;
$stop_reason = $stop_reason.“Email address does not appear to be valid.
”;
}

$telephone_exp = ‘/[1]*$/’;
if(!preg_match($telephone_exp,$telephone_from)) {
$stop = ‘1’;
$stop_reason = $stop_reason.‘The Telephone number you entered does not appear to be valid.
’;
}

$string_exp = “/[2]+$/”;
if(!preg_match($string_exp,$full_name)) {
$stop = ‘1’;
$stop_reason = $stop_reason.‘The Full Name you entered does not appear to be valid.
’;
}
if(strlen($message) < 2) {
$stop = ‘1’;
$stop_reason = $stop_reason.‘The Message you entered do not appear to be valid.
’;
}

if(ISSET($stop)){
echo("
Your message was unable to be sent because of the following:



“.$stop_reason.”


Please feel free to try again.
");
UNSET($stop);
exit;
}

$email_message = “Form details below.\n\n”;

function clean_string($string) {
$bad = array(“content-type”,“bcc:”,“to:”,“cc:”,“href”);
return str_replace($bad,“”,$string);
}

$email_message .= “Full Name: “.clean_string($full_name).”\n”;
$email_message .= “Telephone: “.clean_string($telephone).”\n”;
$email_message .= “Email: “.clean_string($email_from).”\n”;
$email_message .= “Message: “.clean_string($message).”\n”;

// create email headers
$headers = 'From: '.$email_from.“\r\n”.
'Reply-To: '.$email_from.“\r\n” .
‘X-Mailer: PHP/’ . phpversion();

if(mail($email_to,$email_subject,$email_message,$headers)) {
echo ‘’;
echo “”;
}else{
echo “There was a problem sending the mail. We’re really sorry about that.”;
}

?>[/code]

It will use php’s own filter_validate function to check the validity of the email address. I did leave their clean_string function in the code, but if you continue having problems, we might have to see if that’s causing an issue.

Personally, I would store the error messages in the script, convert your form to a php page so you can present the errors at the top of the form page as well as restore their data to the form. The way it is set up now, if someone spends 15 minutes writing the body of the email and includes dots as spacers for their phone number, thanks to the scripts awful regex checking, it will refuse to send and they will have to write the whole message over again.


  1. 0-9 ↩︎

  2. A-Za-z .'- ↩︎

Sorry I mean it displays this echo message so it is successful, but no emails in mailbox

> if(mail($email_to,$email_subject,$email_message,$headers)) { 
>      echo '<script type="text/javascript">alert("Thank you, your request has been submitted!");</script>';
> 	echo "<meta http-equiv='refresh' content='0;url=http://www.momentdesigns.co.za/'>";

If it showed a success message, then I would suggest you echo out your mail submission data to check for errors:

echo $email_to.", ".$email_subject."<br /><br />".$headers."<br /><br />".$email_message;

Drop that in the success if. Make sure everything looks the way it should. If everything does check out, then I would venture to say that your server is stopping the email from sending for one of a myriad of reasons that they do such a thing.

Your code did not have a check to see if the mail was actually sending. The part you quoted is from my code, which actually does check to ensure that the mail function returned successful. Your code would have echoed success no matter what the mail function returned.

Ok well i have done that echo and here is what it displayed:

info@momentdesigns.co.za, Your email subject line

From: gerhard@gmail.com Reply-To: gerhard@gmail.com X-Mailer: PHP/5.4.37

Form details below. Name: Johnathan Telephone: 0446529562 Email: gerhard@gmail.com Message: TEST

I have just changes $email_to = “info@momentdesigns.co.za”; to my other email address $email_to = “jstockenstroom21@gmail.com”; but still not receiving any emails

The script worked just fine for me. (check your info@ email, you should have a test message).

It seems you’re being foiled by your server. Is the mail() function disabled?

I just checked my mailbox still nothing in there. I don’t know how do I check if it is?

I’m not sure I can help you any further Johnathan. I’ve rewritten the mailer script, tested to ensure it worked and sent both you and I an email with the known working script. I got my email and you state you didn’t get that email either, which was known to have sent. This means that your issue is on the email reception end, which is a completely unrelated issue.