subminor Posted June 9, 2009 Share Posted June 9, 2009 Hey all, I'm trying to get my form handler to work. anyone have an answer as to why Im not? I know that the $from email ad is recieving an email, and the $to email doesnt seem to be. also it doesnt redirect and the 'else' is always printed. thanks. PHP code: <?php $to = $_REQUEST['[email protected]'] ; $from = $_REQUEST['email'] ; $name = $_REQUEST['name'] ; $headers = "From: $from"; $subject = "Online Enquiry"; $fields = array(); $fields{"name"} = "Name"; $fields{"email"} = "Email"; $fields{"home_tel"} = "Phone"; $fields{"mob_tel"} = "Mobile"; $fields{"Message"} = "Message"; $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $subject2 = "Thank you for contacting us"; $autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.mysite.com"; if($from == '') {print "You have not entered an email, please go back and try again";} else { if($name == '') {print "You have not entered a name, please go back and try again";} else { $send = mail($to, $subject, $body); $send2 = mail($from, $subject2, $autoreply); if($send) header("Location: http://www.google.com"); else {print "We encountered an error sending your mail, please notify [email protected]"; } } } ?> Link to comment https://forums.phpfreaks.com/topic/161513-solved-this-will-probably-be-easy-for-you-guys/ Share on other sites More sharing options...
947740 Posted June 9, 2009 Share Posted June 9, 2009 var_dump() $_REQUEST and let us know what you get. I would also recommend using $_POST and POST as the form method instead. Link to comment https://forums.phpfreaks.com/topic/161513-solved-this-will-probably-be-easy-for-you-guys/#findComment-852322 Share on other sites More sharing options...
gevans Posted June 9, 2009 Share Posted June 9, 2009 fixed script; <?php $to = '[email protected]'; $from = $_REQUEST['email']; $name = $_REQUEST['name']; $subject = "Online Enquiry"; $fields = array(); $fields["name"] = "Name"; $fields["email"] = "Email"; $fields["home_tel"] = "Phone"; $fields["mob_tel"] = "Mobile"; $fields["Message"] = "Message"; $body = "We have received the following information:\n\n"; foreach($fields as $a => $b) { $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $subject2 = "Thank you for contacting us"; $autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.mysite.com"; if($from == '') { print "You have not entered an email, please go back and try again"; } else { if($name == '') { print "You have not entered a name, please go back and try again"; } else { $send = mail($to, $subject, $body); $send2 = mail($from, $subject2, $autoreply); if($send) { header("Location: http://www.google.com"); exit; } else { print "We encountered an error sending your mail, please notify [email protected]"; } } } ?> Link to comment https://forums.phpfreaks.com/topic/161513-solved-this-will-probably-be-easy-for-you-guys/#findComment-852326 Share on other sites More sharing options...
subminor Posted June 9, 2009 Author Share Posted June 9, 2009 TA...iLL TRY IT. Link to comment https://forums.phpfreaks.com/topic/161513-solved-this-will-probably-be-easy-for-you-guys/#findComment-852330 Share on other sites More sharing options...
subminor Posted June 9, 2009 Author Share Posted June 9, 2009 "Warning: Cannot modify header information - headers already sent by (output started at /home/....." something to do with: header("Location: http://www.google.com"); ??? Link to comment https://forums.phpfreaks.com/topic/161513-solved-this-will-probably-be-easy-for-you-guys/#findComment-852334 Share on other sites More sharing options...
gevans Posted June 9, 2009 Share Posted June 9, 2009 Read the error , you printed to screen before attempting to send a header (headers are already sent by then) change this chunk; <?php if($from == '') { print "You have not entered an email, please go back and try again"; } else { if($name == '') { print "You have not entered a name, please go back and try again"; } else { $send = mail($to, $subject, $body); $send2 = mail($from, $subject2, $autoreply); if($send) { header("Location: http://www.google.com"); exit; } else { print "We encountered an error sending your mail, please notify [email protected]"; } } } to this; <?php if($from == '') { $error = "You have not entered an email, please go back and try again"; } elseif($name == '') { $error = "You have not entered a name, please go back and try again"; } else { $send = mail($to, $subject, $body); $send2 = mail($from, $subject2, $autoreply); if($send) { header("Location: http://www.google.com"); exit; } else { $error = "We encountered an error sending your mail, please notify [email protected]"; } } if(isset($error)) echo $error; Link to comment https://forums.phpfreaks.com/topic/161513-solved-this-will-probably-be-easy-for-you-guys/#findComment-852392 Share on other sites More sharing options...
subminor Posted June 10, 2009 Author Share Posted June 10, 2009 Cheers... All working great!! Link to comment https://forums.phpfreaks.com/topic/161513-solved-this-will-probably-be-easy-for-you-guys/#findComment-853084 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.