Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation ot Getting Mail from my JQuery / Ajax / PHP Contact Form! :(

    Can somebody take a look at it for me and tell me where I'm going wrong? It was a pre-written script so there's no reason for it to be faulty!

    My site is at http://www.stephaniehenderson.com/index_test_c.php
    (My form on that page, links to the jquery library and form plugin scripts, and javascript header script...)

    My sendmail.php code is:
    (Note: I changed my email address to "my@email.com" on purpose)

    Code:
    //        Who you want to recieve the emails from the form. (Hint: generally you.)
    $sendto = 'my@email.com';
    
    //        The subject you'll see in your inbox
    $subject = 'SH Contact Form';
    
    //        Message for the user when he/she doesn't fill in the form correctly.
    $errormessage = 'Oops! There seems to have been a problem. May I suggest...';
    
    //        Message for the user when he/she fills in the form correctly.
    $thanks = "Thanks for the email!";
    
    //        Message for the bot when it fills in in at all.
    $honeypot = "You filled in the honeypot! If you're human, try again!";
    
    //        Various messages displayed when the fields are empty.
    $emptyname =  'Entering your name?';
    $emptyemail = 'Entering your email address?';
    $emptymessage = 'Entering a message?';
    
    //       Various messages displayed when the fields are incorrectly formatted.
    $alertname =  'Entering your name using only the standard alphabet?';
    $alertemail = 'Entering your email in this format: <i>name@example.com</i>?';
    $alertmessage = "Making sure you aren't using any parenthesis or other escaping characters in the message? Most URLS are fine though!";
    
    // --------------------------- Thats it! don't mess with below unless you are really smart! ---------------------------------
    
    //Setting used variables.
    $alert = '';
    $pass = 0;
    
    // Sanitizing the data, kind of done via error messages first. Twice is better!  ;-)
    function clean_var($variable) {
        $variable = strip_tags(stripslashes(trim(rtrim($variable))));
      return $variable;
    }
    
    //The first if for honeypot.
    if ( empty($_REQUEST['last']) ) {
    
    	// A bunch of if's for all the fields and the error messages.
    if ( empty($_REQUEST['name']) ) {
    	$pass = 1;
    	$alert .= "<li>" . $emptyname . "</li>";
    } elseif ( ereg( "[][{}()*+?.\\^$|]", $_REQUEST['name'] ) ) {
    	$pass = 1;
    	$alert .= "<li>" . $alertname . "</li>";
    }
    if ( empty($_REQUEST['email']) ) {
    	$pass = 1;
    	$alert .= "<li>" . $emptyemail . "</li>";
    } elseif ( !eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $_REQUEST['email']) ) {
    	$pass = 1;
    	$alert .= "<li>" . $alertemail . "</li>";
    }
    if ( empty($_REQUEST['message']) ) {
    	$pass = 1;
    	$alert .= "<li>" . $emptymessage . "</li>";
    } elseif ( ereg( "[][{}()*+?\\^$|]", $_REQUEST['message'] ) ) {
    	$pass = 1;
    	$alert .= "<li>" . $alertmessage . "</li>";
    }
    
    	//If the user err'd, print the error messages.
    	if ( $pass==1 ) {
    
    		//This first line is for ajax/javascript, comment it or delete it if this isn't your cup o' tea.
    	echo "<script>$(\".message\").hide(\"slow\").show(\"slow\"); </script>";
    	echo "<b>" . $errormessage . "</b>";
    	echo "<ul>";
    	echo $alert;
    	echo "</ul>";
    
    	// If the user didn't err and there is in fact a message, time to email it.
    	} elseif (isset($_REQUEST['message'])) {
    	    
    		//Construct the message.
    	    $message = "From: " . clean_var($_REQUEST['name']) . "\n";
    		$message .= "Email: " . clean_var($_REQUEST['email']) . "\n";
    	    $message .= "Message: \n" . clean_var($_REQUEST['message']);
    	    $header = 'From:'. clean_var($_REQUEST['email']);
    	    
    //Mail the message - for production
    		//mail($sendto, $subject, $message, $header);
    //This is for javascript, 
    		echo "<script>$(\".message\").hide(\"slow\").show(\"slow\").animate({opacity: 1.0}, 4000).hide(\"slow\"); $(':input').clearForm() </script>";
    		echo $thanks;
    		die();
    
    //Echo the email message - for development
    		echo "<br/><br/>" . $message;
    
    	}
    	
    //If honeypot is filled, trigger the message that bot likely won't see.
    } else {
    	echo "<script>$(\".message\").hide(\"slow\").show(\"slow\"); </script>";
    	echo $honeypot;
    }
    ?>

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Cross-posting is frowned upon. See the other response here.
    Are you a Help Vampire?

  • #3
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm sorry. I'm new to the forum and (as you can probably tell) desperate. It won't happen again...


  •  

    Tags for this Thread

    Posting Permissions

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