SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:
    HTML Code:
     <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 Code:
    <?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."\n";
        
    $body_message 'Name: '.$field_name."\n";
        
    $body_message .= 'Email: '.$field_email."\n";
        
    $body_message .= 'Mobile: '.$field_mobile."\n";
        
    $body_message .= 'Event Date: '.$field_eventdate."\n";
        
    $body_message .= 'Cars: '.$field_cars."\n";
        
    $body_message .= 'Hours Needed: '.$field_hours."\n";
        
    $body_message .= 'Pick Up: '.$field_pickup."\n";
        
    $body_message .= 'Drop Off: '.$field_dropoff."\n";
        
    $body_message .= 'Passengers: '.$field_passengers."\n";
        
    $body_message .= 'Message: '.$field_message;

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

        
    $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,

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,177
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    Hi ibug. Welcome to the forums.

    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?

  3. #3
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    Hi ibug. Welcome to the forums.

    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?

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

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,177
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by ibug View Post
    would this code fix the issue? ...
    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.

    Code:
    <input type="submit" name="submit" value="Send">
    Then in the PHP you need to check for "submit", something like this:

    Code:
    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'];
    
    
    ...
    
    }

  5. #5
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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 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."\n";
        
    $body_message 'Name: '.$field_name."\n";
        
    $body_message .= 'Email: '.$field_email."\n";
        
    $body_message .= 'Mobile: '.$field_mobile."\n";
        
    $body_message .= 'Event Date: '.$field_eventdate."\n";
        
    $body_message .= 'Cars: '.$field_cars."\n";
        
    $body_message .= 'Hours Needed: '.$field_hours."\n";
        
    $body_message .= 'Pick Up: '.$field_pickup."\n";
        
    $body_message .= 'Drop Off: '.$field_dropoff."\n";
        
    $body_message .= 'Passengers: '.$field_passengers."\n";
        
    $body_message .= 'Message: '.$field_message;

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

        
    $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:
    HTML Code:
      <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>

  6. #6
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,129
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    You need another closing bracket } at the end of your php code
    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."\n"
        
    $body_message 'Name: '.$field_name."\n"
        
    $body_message .= 'Email: '.$field_email."\n"
        
    $body_message .= 'Mobile: '.$field_mobile."\n"
        
    $body_message .= 'Event Date: '.$field_eventdate."\n"
        
    $body_message .= 'Cars: '.$field_cars."\n"
        
    $body_message .= 'Hours Needed: '.$field_hours."\n"
        
    $body_message .= 'Pick Up: '.$field_pickup."\n"
        
    $body_message .= 'Drop Off: '.$field_dropoff."\n"
        
    $body_message .= 'Passengers: '.$field_passengers."\n"
        
    $body_message .= 'Message: '.$field_message

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

        
    $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"])
        
    ?>

  7. #7
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,177
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by ibug View Post
    "Parse error: syntax error, unexpected $end in /home/user/public_html/mail.php on line 48
    This just means there's an error somewhere in your code. I don't know PHP, but all I can see is this:

    PHP Code:
    $body_message 'Name: '.$field_name."\n"
    Looks to me like there should be a dot in there before the =. I.e.

    PHP Code:
    $body_message .= 'Name: '.$field_name."\n"
    Also, the opening bracket at the end of this line

    PHP Code:
    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.

  8. #8
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,129
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    This just means there's an error somewhere in your code. I don't know PHP, but all I can see is this:

    PHP Code:
    $body_message 'Name: '.$field_name."\n"
    Looks to me like there should be a dot in there before the =. I.e.

    PHP Code:
    $body_message .= 'Name: '.$field_name."\n"
    Good catch!, I completely missed that.

  9. #9
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,177
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by cpradio View Post
    Good catch!, I completely missed that.
    Shucks ... maybe I'll learn PHP one day after all.

  10. #10
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  11. #11
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,129
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Hmm, not seeing anything obvious, can you put the following after your if ($_POST['submit']) { line?]
    PHP Code:
    var_dump($_POST); 
    Then paste the output it shows here so I can see it?

  12. #12
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,177
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    All of those that aren't working need an underscore between the words. I.e. instead of this:

    PHP Code:
    $field_eventdate $_POST['Event Date']; 
    $field_hours $_POST['Hours Needed']; 
    $field_pickup $_POST['Pick Up']; 
    $field_dropoff $_POST['Drop Off']; 
    you need this:

    PHP Code:
    $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.

  13. #13
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,129
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    All of those that aren't working need an underscore between the words. I.e. instead of this:

    PHP Code:
    $field_eventdate $_POST['Event Date']; 
    $field_hours $_POST['Hours Needed']; 
    $field_pickup $_POST['Pick Up']; 
    $field_dropoff $_POST['Drop Off']; 
    you need this:

    PHP Code:
    $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

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

  14. #14
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,177
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by cpradio View Post
    looks like it removed the underscores too
    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 ...

  15. #15
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey guys,

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

  16. #16
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,177
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    You're welcome. Glad we could help.

    Quote Originally Posted by ibug View Post
    Couldn't have done it without you guys
    We couldn't have done it without you, either.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •