heathergem Posted October 20, 2007 Share Posted October 20, 2007 When I added bcc in the headers, the .php quit redirecting after the form was sent. Before that it worked just fine. How am I messing up this code? <?php $email = $_REQUEST['email'] ; $name = $_REQUEST['name'] ; $to = $_REQUEST['to'] ; $message = $_REQUEST['message'] ; $subject = $_REQUEST['subject'] ; $headers = "Location: http://www.example.com/thankyou.html \n" ; $headers .= "Bcc: user@example.com \n" ; if (!isset($_REQUEST['email'])) { header( "Location: http://www.example.com" ); } elseif (empty($email) || empty($to)) { ?> <html> <head><title>Error</title></head> <body> <h1>Error</h1> <p> Oops, it appears you forgot to enter either your email address or your recipient's address. Please press the BACK button in your browser and try again. </p> </body> </html> <? } else { mail( $to, $subject, $message, "From: $name <$email>", $headers); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/74021-solved-why-wont-this-mail-redirect/ Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 To keep it simple and error free (since your relateively new to php) I would just add a , emailhere to the current email address. It'll send a copy to both listed email addresses, better than trying to add new variables when you are just starting. If not then put here exactly what is happening when it runs. Quote Link to comment https://forums.phpfreaks.com/topic/74021-solved-why-wont-this-mail-redirect/#findComment-373653 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 $email = $_REQUEST['email'] ; Change that line to $email = $_REQUEST['email'] . ', email@address.com'; Insert the email into the slot where I listed the second email. That should work for you without a problem. Quote Link to comment https://forums.phpfreaks.com/topic/74021-solved-why-wont-this-mail-redirect/#findComment-373654 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 Did that fix your problem? Quote Link to comment https://forums.phpfreaks.com/topic/74021-solved-why-wont-this-mail-redirect/#findComment-373708 Share on other sites More sharing options...
heathergem Posted October 20, 2007 Author Share Posted October 20, 2007 Not quite. I did just as you said and then deleted the headers and changed the last part of the script to: mail( $to, $subject, $message, "From: $name <$email>" ); header ("Location: http://www.heathergemmen.com/thankyou.html" ); } Correct? Otherwise, if I leave it as above, it does send the message to $to and to the BCC email, but then it stays on the php page. I'd like it to redirect to http://www.example.com/thankyou.html ... or perhaps I could add an echo to let them know the action has been successful and to give them a link back to my site. Quote Link to comment https://forums.phpfreaks.com/topic/74021-solved-why-wont-this-mail-redirect/#findComment-373717 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 I meant leave everything you ahd but change that part. Try this <?php $email = $_REQUEST['email'] . ', user@example.com' ; $name = $_REQUEST['name'] ; $to = $_REQUEST['to'] ; $message = $_REQUEST['message'] ; $subject = $_REQUEST['subject'] ; $headers = "Location: http://www.example.com/thankyou.html \n" ; if (!isset($_REQUEST['email'])) { header( "Location: http://www.example.com" ); } elseif (empty($email) || empty($to)) { ?> <html> <head><title>Error</title></head> <body> <h1>Error</h1> <p> Oops, it appears you forgot to enter either your email address or your recipient's address. Please press the BACK button in your browser and try again. </p> </body> </html> <? } else { mail( $to, $subject, $message, "From: $name <$email>", $headers); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/74021-solved-why-wont-this-mail-redirect/#findComment-373721 Share on other sites More sharing options...
heathergem Posted October 20, 2007 Author Share Posted October 20, 2007 I appreciate your help so much. I wish I could deliver a plate of warm cookies and a carton of milk to you. Sadly, it's still not working. I checked the code five times to be sure I had it exactly right. I even tried it with and without the \n at the end of the header line. It's doing the same thing as before: staying on the php page without any error messages. Quote Link to comment https://forums.phpfreaks.com/topic/74021-solved-why-wont-this-mail-redirect/#findComment-373736 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 one second let's rewrite the whole thing Quote Link to comment https://forums.phpfreaks.com/topic/74021-solved-why-wont-this-mail-redirect/#findComment-373739 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 ** This was a quick write up and is just a quick attempt to get you something up and running. <?php if (isset($_POST['submit'])) { // make sure submit is set $errorhandler = ''; if ($_REQUEST['email'] == "") { $errorhandler .= 'email is required.<br />'; } if ($_REQUEST['name'] == "") { $errorhandler .= 'Name is required.<br />'; } if ($_REQUEST['to'] == "") { $errorhandler .= 'To field is required.<br />'; } if ($_REQUEST['message'] == "") { $errorhandler .= "message is required.<br />"; } if ($_REQUEST['subject'] == "") { $errorhandler .= "Subject is required.<br />"; } if ($errorhandler != "") { echo '<span style="color:red;">'; echo $errorhandler; echo '</span>'; } if ($errorhandler == "") { $email = $_REQUEST['email'] . ', user@example.com'; $name = $_REQUEST['name'] ; $to = $_REQUEST['to'] ; $message = $_REQUEST['message'] ; $subject = $_REQUEST['subject'] ; mail( $to, $subject, $message, "From: $name <$email>", $headers); header("Location: http://www.example.com/thankyou.html"); } } ?> If this code gives you too many problems then we'll right up something OO style using a class so it'll be easier for you to keep up with and make changes too. Quote Link to comment https://forums.phpfreaks.com/topic/74021-solved-why-wont-this-mail-redirect/#findComment-373741 Share on other sites More sharing options...
heathergem Posted October 20, 2007 Author Share Posted October 20, 2007 I copied and pasted your code, changed only the addresses to my email/site ... and it did the same thing: stayed on the php page. This time the messages did not go through either. Could it be an external problem? I think maybe i'll go back to the way it was without the bcc. I don't need to be copied on the message anyway; that was simply to alleviate my curiosity. The main thing is that viewers can direct others to my site. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/74021-solved-why-wont-this-mail-redirect/#findComment-373758 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 Revert back to your original code. Did you do the , emailaddresshere in your original code as I asked in the beginning. If not then try that. It's suppose to be able to take as many email addresses (separeted by comma's). If this doesn't work, then tell me what is your level of php experience. Perhaps I can help you put together something new that'll do what you are wanting. Quote Link to comment https://forums.phpfreaks.com/topic/74021-solved-why-wont-this-mail-redirect/#findComment-373763 Share on other sites More sharing options...
heathergem Posted October 20, 2007 Author Share Posted October 20, 2007 Okay, here's what I ended up with (see below). It copies me and assures the sender that the action has been completed. I believe it is also secure from spammers. (Correct?) As for my level, I'm very much a beginner—but I'm a motivated learner. You have helped me tremendously. <?php $email = $_REQUEST['email'] ; $name = $_REQUEST['name'] ; $to = $_REQUEST['to'] ; $message = $_REQUEST['message'] ; $subject = $_REQUEST['subject'] ; $header = "bcc: user@mail.com" ; if (!isset($_REQUEST['email'])) { header( "Location: http://www.example.com" ); } elseif (empty($email) || empty($to)) { ?> <html> <head><title>Error</title></head> <body> <h1>Error</h1> <p> Oops. It appears you forgot to enter either your email address or your recipient's address. Please press the BACK button in your browser and try again. </p> </body> </html> <? } else { mail( $to, $subject, $message, "From: $name <$email>", $header); echo ("Your message has been sent.") ; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/74021-solved-why-wont-this-mail-redirect/#findComment-373776 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 You are not safe from mail header injections, however that's getting into a deep subject. http://www.securephpwiki.com/index.php/Email_Injection Read that carefully, but back up your code before making any changes. Quote Link to comment https://forums.phpfreaks.com/topic/74021-solved-why-wont-this-mail-redirect/#findComment-373779 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.