I Can't Get This Contact Form To Work!!! AGHH!!

Discussion in 'PHP' started by coreygeer, Mar 13, 2012.

  1. #1
    Ok, I have a Contact form with four different fields to be submitted. However, when I use the form.. when people click "Submit" it goes through and even goes to the follow up page but it will not send e-mails and this is infuriating. If anyone sees any errors or something I have overlooked.. please let me know.

    Here is the code for the HTML page (Where the contact form is)
    <div id="contact-wrap">     <form action="contact-sent.php" method="post" name="contact" enctype="text/plain">
         	<div id="contact-reason">
            <select name="reason" style='width:150px;height:20px;'>
    <option value="question">I have a question</option>
    <option value="comment">I have a comment/bug/glitch report</option>
    <option value="suggestion">I have a suggestion</option>
    <option value="other">Other</option>
    </select>
            </div>
         	<div id="contact-first-name"><input type="text" name="firstname" style='width:100px;height:18px;border:hidden;background-image:url(images/contact-100-width.png);opacity:0.6;filter:alpha(opacity=60);'/></div>
            <div id="contact-armory-link"><input type="text" name="armory" style='width:400px;height:18px;border:hidden;background-image:url(images/contact-400-width.png);opacity:0.6;filter:alpha(opacity=60);'/></div>
            <div id="contact-e-mail"><input type="text" name="e-mail" style='width:200px;height:18px;border:hidden;background-image:url(images/contact-200-width.png);opacity:0.6;filter:alpha(opacity=60);'/></div>
            <div id="contact-message"><textarea name="message" style='width:560px;height:133px;background-image:url(images/contact-message-area.png);opacity:0.6;filter:alpha(opacity=60);resize:none;'/></textarea></div>
            <div id="contact-submit"><input type="submit" value="Submit" style='width:150px;height:100px;border:hidden;background-image:url(images/contact-submit.png);opacity:0.6;filter:alpha(opacity=60);'/></div>
         </form>
         </div>
    Code (markup):
    And here is the code for the PHP the contact-sent.php file

    <?phpif(isset($_POST['email'])) {
         
        // EDIT THE 2 LINES BELOW AS REQUIRED
        $email_to = "admin@kbwarriors.com";
        $email_subject = "KB Warriors Contact Form";
         
         
        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.<br /><br />";
            echo $error."<br /><br />";
            echo "Please go back and fix these errors.<br /><br />";
            die();
        }
         
        // validation expected data exists
        if(!isset($_POST['firstname']) ||
            !isset($_POST['e-mail']) ||
    		!isset($_POST['armory']) ||
    		!isset($_POST['reason']) ||
            !isset($_POST['message'])) {
            died('We are sorry, but there appears to be a problem with the form you submitted.');       
        }
        $comments = $_POST['reason']; // required
        $first_name = $_POST['firstname']; // required
        $email_from = $_POST['e-mail']; // required
    	$comments = $_POST ['armory'];
        $comments = $_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.<br />';
      }
        $string_exp = "/^[A-Za-z .'-]+$/";
      if(!preg_match($string_exp,$first_name)) {
        $error_message .= 'The First Name you entered does not appear to be valid.<br />';
      }
      if(!preg_match($string_exp,$last_name)) {
        $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
      }
      if(strlen($comments) < 2) {
        $error_message .= 'The Comments you entered do not appear to be valid.<br />';
      }
      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 .= "Reason For Contact: ".clean_string($reason)."\n";
        $email_message .= "First Name: ".clean_string($firstname)."\n";
    	$email_message .= "Armory: ".clean_string($armory). "\n";
        $email_message .= "Email: ".clean_string($e-mail)."\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);  
    ?>
     
    <!-- include your own success html here -->
     
    Thank you for contacting us. We will be in touch with you very soon.
     
    <?php
    }
    ?>
    Code (markup):
     
    coreygeer, Mar 13, 2012 IP
  2. Bank Developer

    Bank Developer Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Is your mail function returning TRUE ?
     
    Bank Developer, Mar 14, 2012 IP