Contact form does nothing when hit submit, little help please?

Discussion in 'PHP' started by Pizzaman1123, Jul 23, 2012.

  1. #1
    I got this contact template and all it says was to enter my email in between the "" in the send_mail.php file which I did. The form does nothing though, no error or anything. What could it be missing or why would it not work out of the box if it was created for the public to use. Please help, Thank you!!

    HTML form
    <form>
    			<input type="text" placeholder="Your Name...">
    			<input type="email" placeholder="Your Email...">
    			<textarea placeholder="Your Message..."></textarea>
    			<input type="submit" value="Submit &rarr;" class="dropsubmitbtn">
    		</form>
    Code (markup):
    send_mail.php
    <?php
    /*
    This first bit sets the email address that you want the form to be submitted to.
    You will need to change this value to a valid email address that you can access.
    */
    $webmaster_email = ""; /* ENTER EMAIL ADDRESS TO THE LEFT INSIDE THE QUOTES */
    
    /*
    This bit sets the URLs of the supporting pages.
    If you change the names of any of the pages, you will need to change the values here.
    */
    $feedback_page = "index.html";
    $error_page = "error.html";
    $thankyou_page = "thanks.html";
    
    /*
    This next bit loads the form field data into variables.
    If you add a form field, you will need to add it here.
    */
    $name = $_REQUEST['name'] ;
    $email_address = $_REQUEST['email_address'] ;
    $comments = $_REQUEST['message'] ;
    
    /*
    The following function checks for email injection.
    Specifically, it checks for carriage returns - typically used by spammers to inject a CC list.
    */
    function isInjected($str) {
    	$injections = array('(\n+)',
    	'(\r+)',
    	'(\t+)',
    	'(%0A+)',
    	'(%0D+)',
    	'(%08+)',
    	'(%09+)'
    	);
    	$inject = join('|', $injections);
    	$inject = "/$inject/i";
    	if(preg_match($inject,$str)) {
    		return true;
    	}
    	else {
    		return false;
    	}
    }
    
    // If the user tries to access this script directly, redirect them to the feedback form,
    if (!isset($_REQUEST['email_address'])) {
    header( "Location: $feedback_page" );
    }
    
    // If the form fields are empty, redirect to the error page.
    elseif (empty($email_address) || empty($comments)) {
    header( "Location: $error_page" );
    }
    
    // If email injection is detected, redirect to the error page.
    elseif ( isInjected($email_address) ) {
    header( "Location: $error_page" );
    }
    
    // If we passed all previous tests, send the email then redirect to the thank you page.
    else {
    mail( "$webmaster_email", "Message from your Atlas site",  
      $name, $comments, "From: $email_address" );
    header( "Location: $thankyou_page" );
    }
    ?>
    Code (markup):

     
    Pizzaman1123, Jul 23, 2012 IP
  2. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #2
    Didn't even read the PHP because that HTML form doesn't even submit to anywhere. You have to specify an action (where the form is sent to) and a method (either post or get, usually you'll use post).
    You also have to give your inputs name.

    
    <form action="send_mail.php" method="post">
                 <input name="name" type="text" placeholder="Your Name...">
                 <input name="email_address" type="email" placeholder="Your Email...">
                 <textarea name="message" placeholder="Your Message..."></textarea>
                 <input type="submit" value="Submit &rarr;" class="dropsubmitbtn">
    </form>
     
    HTML:
     
    blueparukia, Jul 23, 2012 IP
  3. Pizzaman1123

    Pizzaman1123 Peon

    Messages:
    219
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Oh my GOSH! Thank you!! I actually thought about that like a hundred times but did nothing about it because I wasn't sure how to go about it or much about forms really. That's why I love posting stuff here! :)

    My issue now is that when I receive emails from the form I get "Mail Delivery System" as sent "from" and the input of who sent the email isn't anywhere in the email, although the subject and message is.

     
    Pizzaman1123, Jul 23, 2012 IP