engenx Posted August 24, 2011 Share Posted August 24, 2011 <?php if(!$_POST) exit; $email = $_POST['email']; //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS'; if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){ $error.="Invalid email address entered"; $errors=1; } if($errors==1) echo $error; else{ $values = array ('name','email','message'); $required = array('name','email','message'); $your_email = "[email protected]"; $email_subject = "New Message: ".$_POST['subject']; $email_content = "new message:\n"; foreach($values as $key => $value){ if(in_array($value,$required)){ if ($key != 'subject' && $key != 'company') { if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; } } $email_content .= $value.': '.$_POST[$value]."\n"; } } if(@mail($your_email,$email_subject,$email_content)) { header("Location: http://www.temporary.com"); } else { echo 'ERROR!'; } } ?> That is the contact.php file i'm using. The information is sending but after the user submits the information the redirect is going to contact.php instead of the Location address I noted above. Also, on IE9 the Echo I replaced with header("Location..."); is showing up saying thanks while on sitename.com/contact.php and while in Chrome it's just blank. Both instances do not redirect. Please help. I'm extremely frustrated. Thanks. Link to comment https://forums.phpfreaks.com/topic/245548-php-processor-redirect/ Share on other sites More sharing options...
jcbones Posted August 24, 2011 Share Posted August 24, 2011 Try running this: Let us know what the error says. <?php error_reporting(E_ALL); ini_set('display_errors',1); if(!$_POST) exit; $email = $_POST['email']; //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS'; if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){ $error.="Invalid email address entered"; $errors=1; } if($errors==1) echo $error; else{ $values = array ('name','email','message'); $required = array('name','email','message'); $your_email = "[email protected]"; $email_subject = "New Message: ".$_POST['subject']; $email_content = "new message:\n"; foreach($values as $key => $value){ if(in_array($value,$required)){ if ($key != 'subject' && $key != 'company') { if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; } } $email_content .= $value.': '.$_POST[$value]."\n"; } } if(mail($your_email,$email_subject,$email_content) !== false) { header('Status: 200'); //for Chrome. header("Location: http://www.temporary.com"); } else { echo 'ERROR!'; } } ?> Link to comment https://forums.phpfreaks.com/topic/245548-php-processor-redirect/#findComment-1261165 Share on other sites More sharing options...
engenx Posted August 24, 2011 Author Share Posted August 24, 2011 Notice: Undefined variable: errors in /home/content/57/8284857/html/contact.php on line 15 Notice: Undefined index: subject in /home/content/57/8284857/html/contact.php on line 21 Warning: Cannot modify header information - headers already sent by (output started at /home/content/57/8284857/html/contact.php:15) in /home/content/57/8284857/html/contact.php on line 34 Warning: Cannot modify header information - headers already sent by (output started at /home/content/57/8284857/html/contact.php:15) in /home/content/57/8284857/html/contact.php on line 35 This was produced by IE9. Chrome behaved as before (blank screen) sent to contact.php. Link to comment https://forums.phpfreaks.com/topic/245548-php-processor-redirect/#findComment-1261184 Share on other sites More sharing options...
jcbones Posted August 24, 2011 Share Posted August 24, 2011 <?php error_reporting(E_ALL); ini_set('display_errors',1); if(!$_POST) exit; $email = $_POST['email']; //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS'; if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){ //eregi is depreciated, use preg_match functions. $error.="Invalid email address entered"; $errors=1; } if($errors == 1) { echo $error; } //php complaining about an output here causing the header to fail, don't know why as there should be no output unless $errors == 1, wrapped if statement in brackets to see if it stops it. else{ $values = array ('name','email','message'); $required = array('name','email','message'); $your_email = "[email protected]"; $email_subject = "New Message: ".$_POST['subject']; //php complains because there is NO subject to get the data from, check your form and make sure spelling is right. $email_content = "new message:\n"; foreach($values as $key => $value){ if(in_array($value,$required)){ if ($key != 'subject' && $key != 'company') { if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; } } $email_content .= $value.': '.$_POST[$value]."\n"; } } if(mail($your_email,$email_subject,$email_content) !== false) { header('Status: 200'); //for Chrome. header("Location: http://www.temporary.com"); } else { echo 'ERROR!'; } } ?> Link to comment https://forums.phpfreaks.com/topic/245548-php-processor-redirect/#findComment-1261189 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.