worldcomingtoanend Posted October 21, 2009 Share Posted October 21, 2009 I have the code below and even if i enter the correct address on the form it executes the function i have defined that echoes "Invalid email submitted - mail not being sent". i have tested the script on my local pc server and it works well but when i put in on my live server it gives me an error. where could i be going wrong. thanks <?php $to = "[email protected]"; $subject = $_REQUEST["subject"]; $body = $_REQUEST["body"]; $email = $_REQUEST["email"]; $dodgy_strings = array( "content-type:" ,"mime-version:" ,"multipart/mixed" ,"bcc:" ); function is_valid_email($email) { return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s]+\.+[a-z]{2,6}))$#si', $email); } function contains_bad_str($str_to_test) { $bad_strings = array( "content-type:" ,"mime-version:" ,"multipart/mixed" ,"Content-Transfer-Encoding:" ,"bcc:" ,"cc:" ,"to:" ); foreach($bad_strings as $bad_string) { if(preg_match('/'.preg_quote($bad_string,'/').'/i', strtolower($str_to_test))) { echo "$bad_string found. Suspected injection attempt - mail not being sent."; exit; } } } function contains_newlines($str_to_test) { if(preg_match("/(%0A|%0D|\\n+|\\r+)/i", $str_to_test) != 0) { echo "newline found in $str_to_test. Suspected injection attempt - mail not being sent."; exit; } } if($_SERVER['REQUEST_METHOD'] != "POST"){ echo("Unauthorized attempt to access page."); exit; } if (!is_valid_email($email)) { echo 'Invalid email submitted - mail not being sent.'; exit; } contains_bad_str($email); contains_bad_str($subject); contains_bad_str(body); contains_newlines($email); contains_newlines($subject); $headers = "From: $email"; mail($to, $subject, $body, $headers); echo "Thanks for submitting."; ?> Link to comment https://forums.phpfreaks.com/topic/178481-why-is-my-php-script-giving-me-an-error-despite-entering-the-correct-email/ Share on other sites More sharing options...
Pawn Posted October 21, 2009 Share Posted October 21, 2009 I'd recommend using a proper RFC-compliant email validation class like this one. Link to comment https://forums.phpfreaks.com/topic/178481-why-is-my-php-script-giving-me-an-error-despite-entering-the-correct-email/#findComment-941195 Share on other sites More sharing options...
MadTechie Posted October 21, 2009 Share Posted October 21, 2009 for debugging change if (!is_valid_email($email)) { echo 'Invalid email submitted - mail not being sent.'; exit; } to if (!is_valid_email($email)) { echo "[$email] Invalid email submitted - mail not being sent."; exit; } Link to comment https://forums.phpfreaks.com/topic/178481-why-is-my-php-script-giving-me-an-error-despite-entering-the-correct-email/#findComment-941199 Share on other sites More sharing options...
worldcomingtoanend Posted October 21, 2009 Author Share Posted October 21, 2009 surprisingly nothing changes even after trying to debug Link to comment https://forums.phpfreaks.com/topic/178481-why-is-my-php-script-giving-me-an-error-despite-entering-the-correct-email/#findComment-941211 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.