...

View Full Version : ot Getting Mail from my JQuery / Ajax / PHP Contact Form! :(



poetnpink87
01-11-2010, 02:52 AM
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)



// 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;
}
?>

tomws
01-11-2010, 03:15 AM
Cross-posting is frowned upon. See the other response here (http://www.codingforums.com/showthread.php?t=186420).

poetnpink87
01-11-2010, 03:36 AM
I'm sorry. I'm new to the forum and (as you can probably tell) desperate. It won't happen again...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum