WordPress.org

Forums

contact form not working (1 post)

  1. dmd54
    Member
    Posted 2 years ago #

    hoping someone can maybe help with this. i can't figure out why the contact form on the home page is not working, it just loads a 3 when you press submit.

    http://macrodiver.com

    this is the form php

    <div id="quickContact">
    
    	<p id="success" class="successmsg" style="display:none;">Great Success! You're going to hear from us real soon!</p>
    
    				<p id="bademail" class="errormsg" style="display:none;">Hold the phone. Something went wrong. Please check your email and try again.</p>
    				<p id="badserver" class="errormsg" style="display:none;">Looks like we have some technical difficulties. Please try later.</p>			
    
    			<div class="inside">
    
    					<form action="http://macrodiver.com/wp-content/themes/macrodiver/sendmail.php" method="post" id="quickContactForm">
    
    						<input type="text" placeholder="Full Name" name="name" />
    						<input type="email" placeholder="Email Address" name="email" />
    						<input type="text" placeholder="Course Interested In" name="name" />
    						<textarea name="comment" placeholder="">
    </textarea>
    <input type="submit" name="submit" id="submitinput" value="Send"/>
    					<input type="hidden" id="quickReceiver" name="receiver" value="64616e7061796d6172406d652e636f6d"/>
    
    </form>
    
    			</div>	<!-- END OF INSIDE -->

    and this is the sendmail.php

    <?php
      		if(isset($_POST['submit'])) {
              error_reporting(E_NOTICE);
              function valid_email($str)
              {
              return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
    		     }
              if($_POST['name']!='' && $_POST['email']!='' && valid_email($_POST['email'])==TRUE && strlen($_POST['comment'])>1)
              {
                  $to = preg_replace("([\r\n])", "", hexstr($_POST['receiver']));
    			  $from = preg_replace("([\r\n])", "", $_POST['email']);
    			  $subject = "Website contact message from ".$_POST['name'];
                  $message = $_POST['comment'];
    
    			  $match = "/(bcc:|cc:|content\-type:)/i";
    				if (preg_match($match, $to) ||
    					preg_match($match, $from) ||
    					preg_match($match, $message)) {
    				  die("Header injection detected.");
    				}
                  $headers = "From: ".$from."\r\n";
       			  $headers .= "Reply-to: ".$from."\r\n";
    
            if(mail($to, $subject, $message, $headers))
                  {
                      echo 1; //SUCCESS
                  }
                  else {
                      echo 2; //FAILURE - server failure
                  }
              }
              else {
           	  echo 3; //FAILURE - not valid email
    
              }
    		  }else{
    			 die("Direct access not allowed!");
    		   }
    
    		    function hexstr($hexstr) {
    				  $hexstr = str_replace(' ', '', $hexstr);
    				  $hexstr = str_replace('\x', '', $hexstr);
    				  $retstr = pack('H*', $hexstr);
    				  return $retstr;
    				}
    
          ?>

Topic Closed

This topic has been closed to new replies.

About this Topic