dessolator Posted February 4, 2008 Share Posted February 4, 2008 Hi, I'm creating a reservations page where the user can select either a predefined ammount $25, $50... or a other ammount. I want the script to send out a email receipt before the user user gets transferred to the pre-configured paypal url but I was using headers to redirect it in the if statements but obviously it is saying headers already sent as there is something above it in the if statement, but when I use meta redirects paypal says that the url is messed up. I was wondering if there is any other way to do this as I'm not allowed to use a database? Please find the code below: Form <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Make Donation</title> </head> <body> <table width="200" border="0" align="center" cellpadding="2" cellspacing="2"> <tr> <td><div align="center"><strong>Make Donation</strong></div></td> </tr> <tr> <td><form id="form1" name="form1" method="post" action="form_process.php"> <label> Name: <input type="text" name="name" id="name" /> <br /> <br /> Address: <textarea name="address" id="address" cols="45" rows="5"></textarea> <br /> Email Address:<br /> <input type="text" name="email" id="email" /> <br /> <br /> Phone Number:<br /> <input type="text" name="phonenum" id="phonenum" /> </label> <p>Please select a donation amount below or enter your donation below:</p> <p> <label> <input type="radio" name="ammount" value="25" id="ammount_0" /> $25</label> <br /> <label> <input type="radio" name="ammount" value="50" id="ammount_1" /> $50</label> <br /> <label> <input type="radio" name="ammount" value="100" id="ammount_2" /> $100</label> <br /> <label> <input type="radio" name="ammount" value="250" id="ammount_3" /> $250</label> <br /> <label> <input type="radio" name="otheram" value="otheram" id="otheram" /> Other Ammount (Please enter below)</label> <br /> <label> <input type="text" name="otheramount" id="otheramount" /> </label> <br /> <br /> Send Receipt: <label> <input name="receipt" type="checkbox" id="receipt" value="yes" checked="checked" /> </label> <br /> Do not call: <label> <input name="dontcall" type="checkbox" id="dontcall" value="yes" /> </label> </p> <p> <label> <div align="center"> <input type="submit" name="submit" id="submit" value="Submit" /> <input type="reset" name="reset" id="reset" value="Reset" /> </div> </label> <label> <div align="center"></div> </label> <div align="center"><br /> </div> </p> </form> </td> </tr> <tr> <td> </td> </tr> </table> </body> </html> Process page <?php $name = substr($_POST['name'], 0, 65); $address = substr($_POST['address'], 0, 300); $email = substr($_POST['email'], 0, 65); $phone = substr($_POST['phone'], 0, 65); $ammount = substr($_POST['ammount'], 0, 65); $otheramount = substr($_POST['otheramount'], 0, 65); $receipt = substr($_POST['receipt'], 0, 65); $dontcall = substr($_POST['dontcall'], 0, 65); if ($ammount == "25"){ $body = "Donation Successful for 25 dollars"; $to = "test@test.com"; $subject = "Donation Confirmation"; $from = "test@test.com"; $headers = "From: $from"; mail($to, $subject, $body, $headers); header("location:https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=holloway%2eian%40gmail%2ecom&item_name=Donation&amount=25.00&no_shipping=0&no_note=1¤cy_code=USD&lc=US&bn=PP%2dBuyNowBF&charset=UTF%2d8"); exit(); } elseif ($ammount == "50"){ $body = "Donation Successful for 50 dollars"; $to = "test@test.com"; $subject = "Donation Confirmation"; $from = "test@test.com"; $headers = "From: $from"; mail($to, $subject, $body, $headers); header("location:https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=holloway%2eian%40gmail%2ecom&item_name=Donation&amount=50.00&no_shipping=0&no_note=1¤cy_code=USD&lc=US&bn=PP%2dBuyNowBF&charset=UTF%2d8"); exit(); } elseif ($ammount == "100"){ $body = "Donation Successful for 100 dollars"; $to = "test@test.com"; $subject = "Donation Confirmation"; $from = "test@test.com"; $headers = "From: $from"; mail($to, $subject, $body, $headers); header("location:https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=holloway%2eian%40gmail%2ecom&item_name=Donation&amount=100.00&no_shipping=0&no_note=1¤cy_code=USD&lc=US&bn=PP%2dBuyNowBF&charset=UTF%2d8"); } elseif ($ammount == "200"){ $body = "Donation Successful for 200 dollars"; $to = "test@test.com"; $subject = "Donation Confirmation"; $from = "test@test.com"; $headers = "From: $from"; mail($to, $subject, $body, $headers); header("location:https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=holloway%2eian%40gmail%2ecom&item_name=Donation&amount=200.00&no_shipping=0&no_note=1¤cy_code=USD&lc=US&bn=PP%2dBuyNowBF&charset=UTF%2d8"); } elseif ($ammount == "otheram"){ $body = "Donation Successful for $otherammount dollars"; $to = "test@test.com"; $subject = "Donation Confirmation"; $from = "test@test.com"; $headers = "From: $from"; mail($to, $subject, $body, $headers); header("location:https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=holloway%2eian%40gmail%2ecom&item_name=Donation&amount=$otheramount%2e00&no_shipping=0&no_note=1¤cy_code=USD&lc=US&bn=PP%2dBuyNowBF&charset=UTF%2d8"); } ?> Thanks, Ian Quote Link to comment Share on other sites More sharing options...
Sam Granger Posted February 4, 2008 Share Posted February 4, 2008 Have you tried removing all header's and placing one at bottom of page on its own with the ammount variable in it? Quote Link to comment Share on other sites More sharing options...
dessolator Posted February 4, 2008 Author Share Posted February 4, 2008 Hi, thanks for your reply. I have just tried it and is still giving me a "Warning: Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\donation\form_process.php:18) in D:\xampp\htdocs\donation\form_process.php on line 60" message. I have just tried setting up another set of if statments and assigning a new variable in the top if statements and now its not giving me errors but isn't redirecting. New code: <?php $name = substr($_POST['name'], 0, 65); $address = substr($_POST['address'], 0, 300); $email = substr($_POST['email'], 0, 65); $phone = substr($_POST['phone'], 0, 65); $ammount = substr($_POST['ammount'], 0, 65); $otheramount = substr($_POST['otheramount'], 0, 65); $receipt = substr($_POST['receipt'], 0, 65); $dontcall = substr($_POST['dontcall'], 0, 65); if ($ammount == "25"){ $body = "Donation Successful for 25 dollars"; $to = "test@test.com"; $subject = "Donation Confirmation"; $from = "test@test.com"; $headers = "From: $from"; mail($to, $subject, $body, $headers); $ammount1 == $ammount; } elseif ($ammount == "50"){ $body = "Donation Successful for 50 dollars"; $to = "test@test.com"; $subject = "Donation Confirmation"; $from = "test@test.com"; $headers = "From: $from"; mail($to, $subject, $body, $headers); $ammount1 == $ammount; } elseif ($ammount == "100"){ $body = "Donation Successful for 100 dollars"; $to = "test@test.com"; $subject = "Donation Confirmation"; $from = "test@test.com"; $headers = "From: $from"; mail($to, $subject, $body, $headers); $ammount1 == $ammount; } elseif ($ammount == "200"){ $body = "Donation Successful for 200 dollars"; $to = "test@test.com"; $subject = "Donation Confirmation"; $from = "test@test.com"; $headers = "From: $from"; mail($to, $subject, $body, $headers); $ammount1 == $ammount; } elseif ($ammount == "otheram"){ $body = "Donation Successful for $otherammount dollars"; $to = "test@test.com"; $subject = "Donation Confirmation"; $from = "test@test.com"; $headers = "From: $from"; mail($to, $subject, $body, $headers); $ammount1 == $ammount; } ?> <?php if ($ammount1 == "25"){ header("location:https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=holloway%2eian%40gmail%2ecom&item_name=Donation&amount=25.00&no_shipping=0&no_note=1¤cy_code=USD&lc=US&bn=PP%2dBuyNowBF&charset=UTF%2d8"); } elseif ($ammount1 == "50"){ header("location:https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=holloway%2eian%40gmail%2ecom&item_name=Donation&amount=50.00&no_shipping=0&no_note=1¤cy_code=USD&lc=US&bn=PP%2dBuyNowBF&charset=UTF%2d8"); exit(); } elseif ($ammount1 == "100"){ header("location:https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=holloway%2eian%40gmail%2ecom&item_name=Donation&amount=100.00&no_shipping=0&no_note=1¤cy_code=USD&lc=US&bn=PP%2dBuyNowBF&charset=UTF%2d8"); } elseif ($ammount1 == "200"){ header("location:https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=holloway%2eian%40gmail%2ecom&item_name=Donation&amount=200.00&no_shipping=0&no_note=1¤cy_code=USD&lc=US&bn=PP%2dBuyNowBF&charset=UTF%2d8"); } elseif ($ammount1 == "otheram"){ header("location:https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=holloway%2eian%40gmail%2ecom&item_name=Donation&amount=$otheramount%2e00&no_shipping=0&no_note=1¤cy_code=USD&lc=US&bn=PP%2dBuyNowBF&charset=UTF%2d8"); } ?> Thanks, Ian Quote Link to comment Share on other sites More sharing options...
mikefrederick Posted February 4, 2008 Share Posted February 4, 2008 take out the if statements and elseifs at the bottom and put $ammount1 into the url for paypal and then you can just have one header statement Quote Link to comment Share on other sites More sharing options...
dessolator Posted February 4, 2008 Author Share Posted February 4, 2008 Hi, thanks for the reply. Just tried it and still getting the headers already sent message, must be because of the email headers. <?php $name = substr($_POST['name'], 0, 65); $address = substr($_POST['address'], 0, 300); $email = substr($_POST['email'], 0, 65); $phone = substr($_POST['phone'], 0, 65); $ammount = substr($_POST['ammount'], 0, 65); $otheramount = substr($_POST['otheramount'], 0, 65); $receipt = substr($_POST['receipt'], 0, 65); $dontcall = substr($_POST['dontcall'], 0, 65); if ($ammount == "25"){ $body = "Donation Successful for 25 dollars"; $to = "test@test.com"; $subject = "Donation Confirmation"; $from = "test@test.com"; $headers = "From: $from"; mail($to, $subject, $body, $headers); $ammount1 == $ammount; } elseif ($ammount == "50"){ $body = "Donation Successful for 50 dollars"; $to = "test@test.com"; $subject = "Donation Confirmation"; $from = "test@test.com"; $headers = "From: $from"; mail($to, $subject, $body, $headers); $ammount1 == $ammount; } elseif ($ammount == "100"){ $body = "Donation Successful for 100 dollars"; $to = "test@test.com"; $subject = "Donation Confirmation"; $from = "test@test.com"; $headers = "From: $from"; mail($to, $subject, $body, $headers); $ammount1 == $ammount; } elseif ($ammount == "200"){ $body = "Donation Successful for 200 dollars"; $to = "test@test.com"; $subject = "Donation Confirmation"; $from = "test@test.com"; $headers = "From: $from"; mail($to, $subject, $body, $headers); $ammount1 == $ammount; } elseif ($ammount == "otheram"){ $body = "Donation Successful for $otherammount dollars"; $to = "test@test.com"; $subject = "Donation Confirmation"; $from = "test@test.com"; $headers = "From: $from"; mail($to, $subject, $body, $headers); $ammount1 == $ammount; } header("location:https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=holloway%2eian%40gmail%2ecom&item_name=Donation&amount=$ammount1&no_shipping=0&no_note=1¤cy_code=USD&lc=US&bn=PP%2dBuyNowBF&charset=UTF%2d8"); ?> Thanks, Ian Quote Link to comment Share on other sites More sharing options...
Sam Granger Posted February 4, 2008 Share Posted February 4, 2008 Strange, I'm trying to duplicate your problem but I don't get any errors, I get redirected to paypal instantly. Quote Link to comment Share on other sites More sharing options...
Sam Granger Posted February 4, 2008 Share Posted February 4, 2008 You dont have any spaces in front or after your php tags? Quote Link to comment Share on other sites More sharing options...
PHP Monkeh Posted February 4, 2008 Share Posted February 4, 2008 Also you should change $ammount1 == $ammount; to $ammount1 = $ammount; at the end of your if() statements. Quote Link to comment Share on other sites More sharing options...
dessolator Posted February 4, 2008 Author Share Posted February 4, 2008 Hi, theres deffinately no spaces before/after the php tags, its redirecting only for $250 and other ammount but isn't passing the price across. All the other values get the header error still even after changing $ammount1 == $ammount to $ammount1 = $ammount. I have cleared the cache to ensure its not old data etc but still getting errors. So confused. Updated code: <?php $name = substr($_POST['name'], 0, 65); $address = substr($_POST['address'], 0, 300); $email = substr($_POST['email'], 0, 65); $phone = substr($_POST['phone'], 0, 65); $ammount = substr($_POST['ammount'], 0, 65); $otheramount = substr($_POST['otheramount'], 0, 65); $receipt = substr($_POST['receipt'], 0, 65); $dontcall = substr($_POST['dontcall'], 0, 65); if ($ammount == "25"){ $body = "Donation Successful for 25 dollars"; $to = "test@test.com"; $subject = "Donation Confirmation"; $from = "test@test.com"; $headers = "From: $from"; mail($to, $subject, $body, $headers); $ammount1 = $ammount; } elseif ($ammount == "50"){ $body = "Donation Successful for 50 dollars"; $to = "test@test.com"; $subject = "Donation Confirmation"; $from = "test@test.com"; $headers = "From: $from"; mail($to, $subject, $body, $headers); $ammount1 = $ammount; } elseif ($ammount == "100"){ $body = "Donation Successful for 100 dollars"; $to = "test@test.com"; $subject = "Donation Confirmation"; $from = "test@test.com"; $headers = "From: $from"; mail($to, $subject, $body, $headers); $ammount1 = $ammount; } elseif ($ammount == "200"){ $body = "Donation Successful for 200 dollars"; $to = "test@test.com"; $subject = "Donation Confirmation"; $from = "test@test.com"; $headers = "From: $from"; mail($to, $subject, $body, $headers); $ammount1 = $ammount; } elseif ($ammount == "otheram"){ $body = "Donation Successful for $otherammount dollars"; $to = "test@test.com"; $subject = "Donation Confirmation"; $from = "test@test.com"; $headers = "From: $from"; mail($to, $subject, $body, $headers); $ammount1 = $ammount; } header("location:https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=holloway%2eian%40gmail%2ecom&item_name=Donation&amount=$ammount1&no_shipping=0&no_note=1¤cy_code=USD&lc=US&bn=PP%2dBuyNowBF&charset=UTF%2d8"); ?> Thanks, Ian Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 4, 2008 Share Posted February 4, 2008 Forgive me, but why the hell do you have all those elseif statements? You're making the problem much harder than it should be. You also have a problem in that you are setting $ammount1 to $ammount. For "otherammount" that will result in a string value instead of a numeric value (in the current code). <?php $name = substr($_POST['name'], 0, 65); $address = substr($_POST['address'], 0, 300); $email = substr($_POST['email'], 0, 65); $phone = substr($_POST['phone'], 0, 65); $ammount = substr($_POST['ammount'], 0, 65); $otheramount = substr($_POST['otheramount'], 0, 65); $receipt = substr($_POST['receipt'], 0, 65); $dontcall = substr($_POST['dontcall'], 0, 65); if ($ammount == "otheram") { $ammount = $otherammount; } if (is_numeric($ammount)) { //Send the email $to = "test@test.com"; $subject = "Donation Confirmation"; $from = "test@test.com"; $headers = "From: $from"; $body = "Donation Successful for $ammount dollars"; mail($to, $subject, $body, $headers); //Redirect to paypal $paypal_loc = "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick"; $paypal_loc += "&business=holloway%2eian%40gmail%2ecom&item_name=Donation"; $paypal_loc += "&amount=$ammount1&no_shipping=0&no_note=1¤cy_code=USD"; $paypal_loc += "&lc=US&bn=PP%2dBuyNowBF&charset=UTF%2d8" header("location:$paypal_loc"); } else { // Value is not a number need to add error condition here } ?> Quote Link to comment Share on other sites More sharing options...
dessolator Posted February 5, 2008 Author Share Posted February 5, 2008 Thanks very much for your help, Haven't been taught any other way to do elseif's, now I know lol. Still getting the damn header errors, really can't see why though (Line 23-29). Thanks, Ian Quote Link to comment Share on other sites More sharing options...
mikefrederick Posted February 5, 2008 Share Posted February 5, 2008 what happens if you take the mail function out Quote Link to comment 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.