function check_email_address($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; } function check_form() { $to = "irohannanavati@gmail.com"; $from = $_POST["Email"] ; $name = $_POST["FirstName"] ; $suggestion = $_POST["Suggestion"] ; $headers = "From: $from"; $subject = "Email from website by: $name"; $fields = array(); $fields{"FirstName"} = "FirstName"; $fields{"LastName"} = "LastName"; $fields{"PhoneNo"} = "PhoneNo"; $fields{"Email"} = "Email"; $fields{"Suggestion"} = "Suggestion"; $body = "We have received the following suggestion:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $headers2 = "From: $to"; $subject2 = "Thank you for contacting us"; $autoreply = "Thank you for contacting us. Your suggestion has been submitted. We will definately look into it."; $send = mail($to, $subject, $body, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2); if($send) { $message = "Thank you for your suggestion."; $_POST["FirstName"] = ""; $_POST["LastName"] = ""; $_POST["PhoneNo"] = ""; $_POST["Email"] = ""; $_POST["Suggestion"] = ""; } else {$message= "Oops! We encountered an error sending your email, please notify feedback@gujarathirabourse.org"; } ?>
} if(!isset($_POST['Submit'])) { $message = ''; ?> } elseif(isset($_POST["Submit"])) { $Email = $_POST["Email"]; $Suggestion = $_POST["Suggestion"]; if (($Email=='') || ($Suggestion=='') ) { $message = 'Please enter information in fields marked with \'*\'.'; ?> } elseif(!check_email_address($Email)) { $message = 'Please enter a valid e-mail address.'; ?> } else { check_form(); } } ?>