Contact Form - Blank Email

Hey guys first time posting, I am currently stuck on a contact form my website. I have looked at the code dozens of times and still can’t see the error. I have done a half dozen contact forms already all working, this one just wont get going though.

Here is the thing, I am receiving the emails but they all appear blank with the heading and still can’t find my error in the code any help would be great, cheers guys

This is what the emails look like:
Name:
Email:
Mobile:
Event Date:
Car/Cars:
Hours Needed:
Pick Up:
Drop Off:
Passengers:
Message:

All emails appear blank with no test text I have entered.

HTML:


 <h2>Contact Form</h2>
			<form id="ContactForm" action="mail.php" method="POST">
					<div>
						<div class="wrapper">
							<span>Name</span>
							<input type="text" class="input" name="Name" placeholder="Enter your full name">
						</div>
                        <div class="wrapper">
							<span>Email</span>
							<input type="text" class="input" name="Email" placeholder="Enter your email address" >
						</div>
                        <div class="wrapper">
							<span>Mobile</span>
                            <input type="text" class="input" name="Mobile" placeholder="Enter your mobile number ">
						</div>
                        <div class="wrapper">
							<span>Event Date</span>
                            <input type="text" class="input" name="Event Date" placeholder="Enter the event date ">
						</div>
                        <div class="wrapper">
							<span>Cars</span>
							<input type="text" class="input" name="Cars" placeholder="Enter your preferred car or cars">
						</div>
  						<div class="wrapper">
							<span>Hours Needed</span>
							<input type="text" class="input" name="Hours Needed" placeholder="Enter how long you need the cars for">								
						</div>
                        <div class="wrapper">
							<span>Pick Up</span>
							<input type="text" class="input" name="Pick Up" placeholder="Enter the suburb of pickup location">								
						</div>
                        <div class="wrapper">
							<span>Drop Off</span>
							<input type="text" class="input" name="Drop Off" placeholder="Enter the suburb of dropoff location">								
						</div>
                        <div class="wrapper">
							<span>Passengers</span>
							<input type="text" class="input" name="Passengers" placeholder="Enter the total number of passengers">								
					 	</div>
                        <div class="textarea_box">
						<span>Your Message</span><textarea name="Message" cols="1" rows="1"> </textarea> 								
						</div>
						<span>&nbsp;</span>
						<a href="contactus.htm" class="button" onClick="document.getElementById('ContactForm').reset()">Clear</a>
						<a href="mail.php" class="button" onClick="document.getElementById('ContactForm').submit()">Send</a>							</div>
						</form>

PHP:

<?php
	$field_name = $_POST['Name'];
	$field_email = $_POST['Email'];
	$field_mobile = $_POST['Mobile'];
	$field_eventdate = $_POST['Event Date'];
	$field_cars = $_POST['Cars'];
	$field_hours = $_POST['Hours Needed'];
	$field_pickup = $_POST['Pick Up'];
	$field_dropoff = $_POST['Drop Off'];
	$field_passengers = $_POST['Passengers'];
	$field_message = $_POST['Message'];

	$mail_to = 'info@mydomain.com.au';
	$subject = 'Contact Form Reply - '.$field_name;
	
	$body_message = 'From: '.$field_name."\
";
	$body_message = 'Name: '.$field_name."\
";
	$body_message .= 'Email: '.$field_email."\
";
	$body_message .= 'Mobile: '.$field_mobile."\
";
	$body_message .= 'Event Date: '.$field_eventdate."\
";
	$body_message .= 'Cars: '.$field_cars."\
";
	$body_message .= 'Hours Needed: '.$field_hours."\
";
	$body_message .= 'Pick Up: '.$field_pickup."\
";
	$body_message .= 'Drop Off: '.$field_dropoff."\
";
	$body_message .= 'Passengers: '.$field_passengers."\
";
	$body_message .= 'Message: '.$field_message;

	$headers = 'From: '.$field_email."\\r\
";
	$headers .= 'Reply-To: '.$field_email."\\r\
";

	$mail_status = mail($mail_to, $subject, $body_message, $headers);

	if ($mail_status) { ?>
	<script language="javascript" type="text/javascript">
			alert('Thank you for the message. We will contact you shortly.');
			window.location = 'contactus.htm';
	</script>
	<?php
	}
	else { ?>
	<script language="javascript" type="text/javascript">
		alert('Message failed. Please, send an email to info@mydomain.com.au');
		window.location = 'contactus.htm';
	</script>
	<?php
	}
	?>

Cheers guys,

Hi ibug. Welcome to the forums. :slight_smile:

This may have nothing to do with the issue at hand, but why are you using links for the clear and submit buttons, rather than proper form inputs?

Hey Ralph,

Not sure really, don’t even take notice of that anymore. I made my first contact form like that and have just copied and pasted that part on all my others since then, would this code fix the issue?

<a href="mail.php" class="button" input type="submit" name="submit" value="Send">Send</a>

No, that’s still a link.

As I say, I mentioned this as an aside, as I’m not sure it’s related to the issue. But you should be using a submit button of some kind rather than a link. E.g.

<input type="submit" name="submit" value="Send">

Then in the PHP you need to check for “submit”, something like this:

[COLOR="#FF0000"]if ($_POST["submit"]) {[/COLOR]
    $field_name = $_POST['Name']; 
    $field_email = $_POST['Email']; 
    $field_mobile = $_POST['Mobile']; 
    $field_eventdate = $_POST['Event Date']; 
    $field_cars = $_POST['Cars']; 
    $field_hours = $_POST['Hours Needed']; 
    $field_pickup = $_POST['Pick Up']; 
    $field_dropoff = $_POST['Drop Off']; 
    $field_passengers = $_POST['Passengers']; 
    $field_message = $_POST['Message'];


...

}

Hey Ralph,

I did as you said and I see what you mean, it is much better than before, however the form works perfectly when testing it but when I upload it to the server it claims an error:

"Parse error: syntax error, unexpected $end in /home/user/public_html/mail.php on line 48

Not sure why it is picking on my closing PHP tags?

Note - This still has not affected the main issue, blank emails still being recieved

PHP:

<?php
	if ($_POST["submit"]) {
	$field_name = $_POST['Name'];
	$field_email = $_POST['Email'];
	$field_mobile = $_POST['Mobile'];
	$field_eventdate = $_POST['Event_Date'];
	$field_cars = $_POST['Cars'];
	$field_hours = $_POST['Hours_Needed'];
	$field_pickup = $_POST['Pick_Up'];
	$field_dropoff = $_POST['Drop_Off'];
	$field_passengers = $_POST['Passengers'];
	$field_message = $_POST['Message'];

	$mail_to = 'info@mydomain.com.au';
	$subject = 'Contact Form Reply - '.$field_name;
	
	$body_message = 'From: '.$field_name."\
";
	$body_message = 'Name: '.$field_name."\
";
	$body_message .= 'Email: '.$field_email."\
";
	$body_message .= 'Mobile: '.$field_mobile."\
";
	$body_message .= 'Event Date: '.$field_eventdate."\
";
	$body_message .= 'Cars: '.$field_cars."\
";
	$body_message .= 'Hours Needed: '.$field_hours."\
";
	$body_message .= 'Pick Up: '.$field_pickup."\
";
	$body_message .= 'Drop Off: '.$field_dropoff."\
";
	$body_message .= 'Passengers: '.$field_passengers."\
";
	$body_message .= 'Message: '.$field_message;

	$headers = 'From: '.$field_email."\\r\
";
	$headers .= 'Reply-To: '.$field_email."\\r\
";

	$mail_status = mail($mail_to, $subject, $body_message, $headers);

	if ($mail_status) { ?>
	<script language="javascript" type="text/javascript">
			alert('Thank you for the message. We will contact you shortly.');
			window.location = 'contactus.htm';
	</script>
	<?php
	}
	else { ?>
	<script language="javascript" type="text/javascript">
		alert('Message failed. Please, send an email to info@mydomain.com.au');
		window.location = 'contactus.htm';
	</script>
	<?php
	}
	?>

HTML:

  <h2>Contact Form</h2>
			<form id="ContactForm" action="mail.php" method="POST">
			  <div>
						<div class="wrapper">
							<span>Name</span>
							<input type="text" class="input" name="Name"placeholder="Enter your full name">
						</div>
                        <div class="wrapper">
							<span>Email</span>
							<input type="text" class="input"  name="Email" placeholder="Enter your email address" >
						</div>
                        <div class="wrapper">
							<span>Mobile</span>
                            <input type="text" class="input"  name="Mobile" placeholder="Enter your mobile number">
						</div>
                        <div class="wrapper">
							<span>Event Date</span>
                            <input type="text" class="input"  name="Event_Date" placeholder="Enter the event date">
						</div>
                        <div class="wrapper">
							<span>Cars</span>
							<input type="text" class="input" name="Cars" placeholder="Enter your preferred car or cars">
						</div>
  						<div class="wrapper">
							<span>Hours Needed</span>
							<input type="text" class="input" name="Hours_Needed" placeholder="Enter how long you need the cars for">								
						</div>
                        <div class="wrapper">
							<span>Pick Up</span>
							<input type="text" class="input" name="Pick_Up" placeholder="Enter the suburb of pickup location">								
						</div>
                        <div class="wrapper">
							<span>Drop Off</span>
							<input type="text" class="input" name="Drop_Off" placeholder="Enter the suburb of dropoff location">								
						</div>
                        <div class="wrapper">
							<span>Passengers</span>
							<input type="text" class="input" name="Passengers" placeholder="Enter the total number of passengers">								
					 	</div>
                        <div class="textarea_box">
						<span>Your Message</span><textarea name="Message" cols="1" rows="1"> </textarea> 								
						</div>
						<span><p></p></span>
                        <input type="submit" name="submit" value="Send"> 
                        <input type="reset" name="clear" value="Clear"> 
											</div>
						</form>

You need another closing bracket } at the end of your php code

<?php 
    if ($_POST["submit"]) { 
    $field_name = $_POST['Name']; 
    $field_email = $_POST['Email']; 
    $field_mobile = $_POST['Mobile']; 
    $field_eventdate = $_POST['Event Date']; 
    $field_cars = $_POST['Cars']; 
    $field_hours = $_POST['Hours Needed']; 
    $field_pickup = $_POST['Pick Up']; 
    $field_dropoff = $_POST['Drop Off']; 
    $field_passengers = $_POST['Passengers']; 
    $field_message = $_POST['Message']; 

    $mail_to = 'info@mydomain.com.au'; 
    $subject = 'Contact Form Reply - '.$field_name; 
     
    $body_message = 'From: '.$field_name."\
"; 
    $body_message = 'Name: '.$field_name."\
"; 
    $body_message .= 'Email: '.$field_email."\
"; 
    $body_message .= 'Mobile: '.$field_mobile."\
"; 
    $body_message .= 'Event Date: '.$field_eventdate."\
"; 
    $body_message .= 'Cars: '.$field_cars."\
"; 
    $body_message .= 'Hours Needed: '.$field_hours."\
"; 
    $body_message .= 'Pick Up: '.$field_pickup."\
"; 
    $body_message .= 'Drop Off: '.$field_dropoff."\
"; 
    $body_message .= 'Passengers: '.$field_passengers."\
"; 
    $body_message .= 'Message: '.$field_message; 

    $headers = 'From: '.$field_email."\\r\
"; 
    $headers .= 'Reply-To: '.$field_email."\\r\
"; 

    $mail_status = mail($mail_to, $subject, $body_message, $headers); 

    if ($mail_status) { ?> 
    <script language="javascript" type="text/javascript"> 
            alert('Thank you for the message. We will contact you shortly.'); 
            window.location = 'contactus.htm'; 
    </script> 
    <?php 
    } 
    else { ?> 
    <script language="javascript" type="text/javascript"> 
        alert('Message failed. Please, send an email to info@mydomain.com.au'); 
        window.location = 'contactus.htm'; 
    </script> 
    <?php 
    } 
 } // close if ($_POST["submit"])
    ?>

This just means there’s an error somewhere in your code. I don’t know PHP, but all I can see is this:

$body_message = 'Name: '.$field_name."\
";

Looks to me like there should be a dot in there before the =. I.e.

$body_message .= 'Name: '.$field_name."\
";

Also, the opening bracket at the end of this line

if ($_POST["submit"]) { 

is not closed at the end of the script, so try adding } at the very end, before the last ?>.

Other than that, we need a trained see to see what’s amiss.

Good catch!, I completely missed that.

Shucks … maybe I’ll learn PHP one day after all. :smiley:

Hey guys,

Fast reply!

Thanks heaps for the tips, still having one last problem. I am now receiving the info bar a few parts this is what a test email looked like:

From: Anthony
Name: Anthony
Email: a@test.com
Mobile: 0424 test
Event Date:
Cars: Hummer
Hours Needed:
Pick Up:
Drop Off:
Passengers: 8
Message: Test

Still missing those 4 fields, but everyone has an _ and no extra spaces that I can see?

Hmm, not seeing anything obvious, can you put the following after your if ($_POST[‘submit’]) { line?]

var_dump($_POST);

Then paste the output it shows here so I can see it?

All of those that aren’t working need an underscore between the words. I.e. instead of this:

$field_eventdate = $_POST['Event Date']; 
$field_hours = $_POST['Hours Needed']; 
$field_pickup = $_POST['Pick Up']; 
$field_dropoff = $_POST['Drop Off']; 

you need this:

$field_eventdate = $_POST['Event_Date']; 
$field_hours = $_POST['Hours_Needed']; 
$field_pickup = $_POST['Pick_Up']; 
$field_dropoff = $_POST['Drop_Off']; 

You must match the name values exactly.

Ha! That ended up being my fault, when I copied and pasted his original code to add the closing bracket, looks like it removed the underscores too :rolleyes:

Another good catch and no wonder I didn’t find it, I compared it to his post which had the underscores :stuck_out_tongue:

You must have copied the original code that was posted, which lacked the underscores. Wow you need sharp eyes in this game. I stared at all that and didn’t see those missing underscores, or the missing dot etc …

Hey guys,

I would like to thank you all for your help everything now works perfectly. Couldn’t have done it without you guys

You’re welcome. Glad we could help. :slight_smile:

We couldn’t have done it without you, either. :lol: :rolleyes: :shifty: