Iluvatar13 Posted March 10, 2010 Share Posted March 10, 2010 So after the failed email form I did yesterday I tried a new one. I first tried the default setup to make sure it worked and it did, then I edited it to work for my actual site (http://thegrowframe.com/retail.html) and now I'm getting the same blank page issue again. I tested the default on the same server so it's not that, I've come to the conclusion it's something wrong with my form page, but haven't been able to figure out just what as of yet. Would appreciate if anyone notices a problem in my form so I can get this working. I've posted both the default mailer (first) and my edited site mailer (second). Default - <html><body><font face=Arial size=2> <form method="post" action="contact.php"> <table bgcolor=#ffffcc align=center> <tr><td colspan=2><strong>Contact us using this form:</strong></td></tr> <tr><td>Department:</td><td><select name="sendto"> <option value="iluvatar13@gmail.com">General</option> <option value="ainurdesign@gmail.com">Support</option> <option value="sales@mycompany.com">Sales</option> </select></td></tr> <tr><td><font color=red>*</font> Name:</td><td><input size=25 name="Name"></td></tr> <tr><td><font color=red>*</font> Email:</td><td><input size=25 name="Email"></td></tr> <tr><td>Company:</td><td><input size=25 name="Company"></td></tr> <tr><td>Phone:</td><td><input size=25 name="Phone"></td></tr> <tr><td>Subscribe to<br> mailing list:</td><td><input type="radio" name="list" value="No"> No Thanks<br> <input type="radio" name="list" value="Yes" checked> Yes, keep me informed<br></td></tr> <tr><td colspan=2>Message:</td></tr> <tr><td colspan=2 align=center><textarea name="Message" rows=5 cols=35></textarea></td></tr> <tr><td colspan=2 align=center><input type=submit name="send" value="Submit"></td></tr> <tr><td colspan=2 align=center><small>A <font color=red>*</font> indicates a field is required</small></td></tr> </table> <?php $to = $_REQUEST['sendto'] ; $from = $_REQUEST['Email'] ; $name = $_REQUEST['Name'] ; $headers = "From: $from"; $subject = "Web Contact Data"; $fields = array(); $fields{"Name"} = "Name"; $fields{"Company"} = "Company"; $fields{"Email"} = "Email"; $fields{"Phone"} = "Phone"; $fields{"list"} = "Mailing List"; $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]); } $headers2 = "From: noreply@YourCompany.com"; $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.oursite.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, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2); if($send) {header( "Location: http://www.YourDomain.com/thankyou.html" );} else {print "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; } } } ?> Edited - http://thegrowframe.com/retail.html <?php //$to = $_REQUEST['sendto'] ; $to = "ainurdesign@gmail.com"; $from = $_REQUEST['Email'] ; $name = $_REQUEST['Contact'] ; $company = $_REQUEST['Company'] ; $phone = $_REQUEST['Phone'] ; $street = $_REQUEST['Street'] ; $city = $_REQUEST['City'] ; $state = $_REQUEST['State'] ; $zip = $_REQUEST['Zip'] ; $interest = $_REQUEST['Interest'] ; $agree = $_REQUEST['Agree'] ; $headers = "From: $from"; $subject = "Retailer Form Information"; $fields = array(); $fields{"Company"} = "Company"; $fields{"Contact"} = "Contact"; $fields{"Email"} = "Email"; $fields{"Phone"} = "Phone"; $fields{"Street"} = "Street"; $fields{"City"} = "City"; $fields{"State"} = "State"; $fields{"Zip"} = "Zip"; $fields{"Interest"} = "Interest"; $fields{"License"} = "License"; $fields{"Business"} = "Business"; $fields{"URL"} = "URL"; $fields{"Comments"} = "Comments"; $fields{"Agree"} = "Agree"; $body = "Wholesaler info is as follows:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $headers2 = "From: Trevor @ GrowShow/GrowFrame.com"; $subject2 = "Thank you for contacting GrowFrame"; $autoreply = "Thank you for contacting us. Someone will get back to you as soon as possible, usually within 48 hours. If you have any immediate questions, please feel free to call our Sales Manager, Traci Elliott, at 1 (805) 407-3471."; if($from == '') {print "You have not entered an email, please return and try again";} else { if($company == '') {print "You have not entered a company name, please return and try again";} else { if($name == '') {print "You have not entered a contact name, please return and try again";} else { if($phone == '') {print "You have not entered a phone number, please return and try again";} else { if($street == '') {print "You have not entered a street address, please return and try again";} else { if($city == '') {print "You have not entered a city, please return and try again";} else { if($state == '') {print "You have not entered a state, please return and try again";} else { if($zip == '') {print "You have not entered a zip code, please return and try again";} else { if($interest == '') {print "You have not entered your selection for drop-shipping or wholesale, please return and try again";} else { if($agree == '') {print "You have not selected Yes to the agreement, please return and try again";} else { $send = mail($to, $subject, $body, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2); if($send) {header( "Location: http://thegrowframe.com/return.html" );} else {print "We encountered an error sending your email, please confirm your address is correct and try again."; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/194817-continued-email-issue/ Share on other sites More sharing options...
Psycho Posted March 10, 2010 Share Posted March 10, 2010 Not to be rude, but I'm not going to read through all of that. But, if you were able to get the "default" setup to work then you can solve this yourself. Start with the default form. Then add some additional functionality you need. Test it. Does it still work? If so, add some more functionality you need. If not, find the error in the code you just added. By adding small bits of functinoality at a time you know exactly what code is causing the problem. When you add a whole bunch of functionality at one time there can be many different errors causing problems making debugging much more difficult. Quote Link to comment https://forums.phpfreaks.com/topic/194817-continued-email-issue/#findComment-1024401 Share on other sites More sharing options...
Psycho Posted March 10, 2010 Share Posted March 10, 2010 OK, I lied. I decided to read through the code. I'm surprised you are not getting any errors. One problem that I see right off is that your else/if are malformed. Each subsequent IF statement is "embedded" in the one before it. So, you would not have enough closing brackets. here is part of your IF/ELSE section with spacing added to see the structure: if($from == '') { print "You have not entered an email, please return and try again"; } else { if($company == '') { print "You have not entered a company name, please return and try again"; } else { if($name == '') { print "You have not entered a contact name, please return and try again"; } else { if($phone == '') { print "You have not entered a phone number, please return and try again"; } I think you meant to do something more like this: if($from == '') { print "You have not entered an email, please return and try again"; } elseif($company == '') { print "You have not entered a company name, please return and try again"; } elseif($name == '') { print "You have not entered a contact name, please return and try again"; } elseif($phone == '') { print "You have not entered a phone number, please return and try again"; } Quote Link to comment https://forums.phpfreaks.com/topic/194817-continued-email-issue/#findComment-1024404 Share on other sites More sharing options...
schilly Posted March 10, 2010 Share Posted March 10, 2010 couple things: I'd change $_REQUEST to either $_POST or $_GET depending what the vars are. I'm assuming $_POST. I didn't even know that curly brackets worked on arrays. $fields{"Name"} but I would change those to hard brackets $fields["Name"] This may or may not work depending on your mail server: $headers2 = "From: Trevor @ GrowShow/GrowFrame.com"; Put an email address in there: $headers2 = "From: Trevor admin@GrowFrame.com"; Put this at the top of your page: ini_set ("display_errors", "1"); error_reporting(E_ALL); Now use comments and echos to find out exactly where it's breaking. Also is there an extra bracket at the bottom. From your formatting I can't tell what that last bracket is closing. edit: ah good catach mjdamato. couldn't figure out that bracket. Quote Link to comment https://forums.phpfreaks.com/topic/194817-continued-email-issue/#findComment-1024405 Share on other sites More sharing options...
roopurt18 Posted March 10, 2010 Share Posted March 10, 2010 if($send) {header( "Location: http://thegrowframe.com/return.html" );} You typically want to call exit() after setting header-location: if($send) {header( "Location: http://thegrowframe.com/return.html" ); exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/194817-continued-email-issue/#findComment-1024408 Share on other sites More sharing options...
Iluvatar13 Posted March 10, 2010 Author Share Posted March 10, 2010 I appreciate the help guys, I took Mjdamato's advice and started adding things a bit at a time and got it working without the extra array variables and error returns, I'll look through the other posts to see if I can get those working. Thanks a lot. Quote Link to comment https://forums.phpfreaks.com/topic/194817-continued-email-issue/#findComment-1024414 Share on other sites More sharing options...
Psycho Posted March 10, 2010 Share Posted March 10, 2010 Here's a rewrite of your original code. I think its a little more efficinet and logically laid out. Give it a try: <?php //$to = $_REQUEST['sendto'] ; $to = "ainurdesign@gmail.com"; //Trim all the values foreach($_REQUEST as $key => $value) { $_REQUEST[$key] = trim($value); } //Check for missing data $errors = array(); if(empty($_REQUEST['Email'])) { $errors{} = "You have not entered an email, please return and try again"; } if(empty($_REQUEST['Company'])) { $errors{} = "You have not entered a company name, please return and try again"; } if(empty(($_REQUEST['Contact'])) { $errors{} = "You have not entered a contact name, please return and try again"; } if(empty($_REQUEST['Phone'])) { $errors{} = "You have not entered a phone number, please return and try again"; } if(empty($_REQUEST['Street'])) { $errors{} = "You have not entered a street address, please return and try again"; } if(empty($_REQUEST['City'])) { $errors{} = "You have not entered a city, please return and try again"; } if(empty($_REQUEST['State'])) { $errors{} = "You have not entered a state, please return and try again"; } if(empty($_REQUEST['Zip'])) { $errors{} = "You have not entered a zip code, please return and try again"; } if(empty($_REQUEST['Interest'])) { $errors{} = "You have not entered your selection for drop-shipping or wholesale, please return and try again"; } if(empty($_REQUEST['Agree'])) { $errors{} = "You have not selected Yes to the agreement, please return and try again"; } if (count($errors)>0) { //There was missing data echo "The following errors occured<br>\n"; echo "<ul>\n"; foreach($errors as $error) { echo "<li>{$error}</li>\n"; } echo "</ul>\n"; } else { //No validation errors, create the email content //Data fro email #1 $subject1 = "Retailer Form Information"; $headers1 = "From: $from"; $body = "Wholesaler info is as follows:\n\n"; $bodyfields = array('Company', 'Contact', 'Email', 'Phone', 'Street', 'City', 'State', 'Zip', 'Interest', 'License', 'Business', 'URL', 'Comments', 'Agree'); foreach($bodyfields as $field) { $body .= sprintf("%20s: %s\n", $field, $_REQUEST[$field]); } //Data for email #2 $subject2 = "Thank you for contacting GrowFrame"; $autoreply = "Thank you for contacting us. Someone will get back to you as soon as possible, usually within 48 hours. If you have any immediate questions, please feel free to call our Sales Manager, Traci Elliott, at 1 (805) 407-3471."; $headers2 = "From: Trevor @ GrowShow/GrowFrame.com"; //Send the emails $send = mail($to, $subject1, $body, $headers1); $send2 = mail($_REQUEST['Email'], $subject2, $autoreply, $headers2); if(!$send || !$send2) { //Errors in sending the emails echo "We encountered an error sending your email, please confirm your address is correct and try again."; } else { //No errors returned header( "Location: http://thegrowframe.com/return.html" ); exit(); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/194817-continued-email-issue/#findComment-1024424 Share on other sites More sharing options...
Iluvatar13 Posted March 11, 2010 Author Share Posted March 11, 2010 Hey again guys, just checking back in to let you know it's all working now. I tried your new version for the error returns Mjdamato but it was giving me a blank page again. So instead of trying to go through all that and re-learn it again I went back and put the missing end brackets you mentioned before (I tried the different formatting you suggested in that post but it made the error returns not work at all and send the info anyway as if nothing was missing). So here's the finished/working code, if you have a suggestion for condensing the considerable amount of end brackets at the end I'm all ears lol. Other than that I'm happy with the end result, thanks for all your help. <?php //$to = $_REQUEST['sendto'] ; $to = "traci@growshow.com" , "ideas@growshow.com"; $from = $_REQUEST['Email'] ; $name = $_REQUEST['Contact'] ; $company = $_REQUEST['Company'] ; $phone = $_REQUEST['Phone'] ; $street = $_REQUEST['Street'] ; $city = $_REQUEST['City'] ; $state = $_REQUEST['State'] ; $zip = $_REQUEST['Zip'] ; $interest = $_REQUEST['Interest'] ; $agree = $_REQUEST['Agree'] ; $headers = "From: $from"; $subject = "Retailer Form Information"; $fields = array(); $fields["Company"] = "Company"; $fields["Contact"] = "Contact"; $fields["Email"] = "Email"; $fields["Phone"] = "Phone"; $fields["Street"] = "Street"; $fields["City"] = "City"; $fields["State"] = "State"; $fields["Zip"] = "Zip"; $fields["Interest"] = "Interest"; $fields["License"] = "License"; $fields["Business"] = "Business"; $fields["URL"] = "URL"; $fields["Comments"] = "Comments"; $fields["Agree"] = "Agree"; $body = "Wholesaler info is as follows:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $headers2 = "From: trevor.elliot@growshow.com"; $subject2 = "Thank you for contacting GrowFrame"; $autoreply = "Thank you for contacting us. Someone will get back to you as soon as possible, usually within 48 hours. If you have any immediate questions, please feel free to call us at 1 (805) 407-3471."; if($from == '') {print "You have not entered an email, please return and try again";} else { if($company == '') {print "You have not entered a company name, please return and try again";} else { if($name == '') {print "You have not entered a contact name, please return and try again";} else { if($phone == '') {print "You have not entered a phone number, please return and try again";} else { if($street == '') {print "You have not entered a street address, please return and try again";} else { if($city == '') {print "You have not entered a city, please return and try again";} else { if($state == '') {print "You have not entered a state, please return and try again";} else { if($zip == '') {print "You have not entered a zip code, please return and try again";} else { if($interest == '') {print "You have not entered your selection for drop-shipping or wholesale, please return and try again";} else { if($agree == '') {print "You have not selected Yes to the agreement, please return and try again";} else { $send = mail($to, $subject, $body, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2); if($send) {header( "Location: http://thegrowframe.com/return.html" ); exit(); } else {print "We encountered an error sending your information, please confirm your email address is correct and try again, or call us at 1 (805) 407-3471."; } } } } } } } } } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/194817-continued-email-issue/#findComment-1024948 Share on other sites More sharing options...
Psycho Posted March 11, 2010 Share Posted March 11, 2010 There wre a couple of minor typos, but you should have received errors on them. Anyway, I have made those corrections and also added a "basic" form to the bottom. If you merge the form and your processing code in this manner you can repopulate the form with what the user entered when there is a validation error. Give it a try <?php if (isset($_POST['submit'])) { $to = "ainurdesign@gmail.com"; //Trim all the values foreach($_POST as $key => $value) { $_POST[$key] = trim($value); } //Check for missing data $errors = array(); if(empty($_POST['Email'])) { $errors[] = "You have not entered an email, please return and try again"; } if(empty($_POST['Company'])) { $errors[] = "You have not entered a company name, please return and try again"; } if(empty($_POST['Contact'])) { $errors[] = "You have not entered a contact name, please return and try again"; } if(empty($_POST['Phone'])) { $errors[] = "You have not entered a phone number, please return and try again"; } if(empty($_POST['Street'])) { $errors[] = "You have not entered a street address, please return and try again"; } if(empty($_POST['City'])) { $errors[] = "You have not entered a city, please return and try again"; } if(empty($_POST['State'])) { $errors[] = "You have not entered a state, please return and try again"; } if(empty($_POST['Zip'])) { $errors[] = "You have not entered a zip code, please return and try again"; } if(empty($_POST['Interest'])) { $errors[] = "You have not entered your selection for drop-shipping or wholesale, please return and try again"; } if(empty($_POST['Agree'])) { $errors[] = "You have not selected Yes to the agreement, please return and try again"; } if (count($errors)>0) { //There was missing data echo "The following errors occured<br>\n"; echo "<ul>\n"; foreach($errors as $error) { echo "<li>{$error}</li>\n"; } echo "</ul>\n"; } else { //No validation errors, create the email content //Data fro email #1 $subject1 = "Retailer Form Information"; $headers1 = "From: $from"; $body = "Wholesaler info is as follows:\n\n"; $bodyfields = array('Company', 'Contact', 'Email', 'Phone', 'Street', 'City', 'State', 'Zip', 'Interest', 'License', 'Business', 'URL', 'Comments', 'Agree'); foreach($bodyfields as $field) { $body .= sprintf("%20s: %s\n", $field, $_POST[$field]); } //Data for email #2 $subject2 = "Thank you for contacting GrowFrame"; $autoreply = "Thank you for contacting us. Someone will get back to you as soon as possible, usually within 48 hours. If you have any immediate questions, please feel free to call our Sales Manager, Traci Elliott, at 1 (805) 407-3471."; $headers2 = "From: Trevor @ GrowShow/GrowFrame.com"; //Send the emails $send = mail($to, $subject1, $body, $headers1); $send2 = mail($_POST['Email'], $subject2, $autoreply, $headers2); if(!$send || !$send2) { //Errors in sending the emails echo "We encountered an error sending your email, please confirm your address is correct and try again."; } else { //No errors returned header( "Location: http://thegrowframe.com/return.html" ); exit(); } } } ?> <html> <body> <form name="" action="" method="POST"> * Email: <input type="text" name="Email" value="<?php echo $_POST['Email']; ?>" /><br /> * Company: <input type="text" name="Company" value="<?php echo $_POST['Company']; ?>" /><br /> * Contact: <input type="text" name="Contact" value="<?php echo $_POST['Contact']; ?>" /><br /> * Phone: <input type="text" name="Phone" value="<?php echo $_POST['Phone']; ?>" /><br /> * Street: <input type="text" name="Street" value="<?php echo $_POST['Street']; ?>" /><br /> * City: <input type="text" name="City" value="<?php echo $_POST['City']; ?>" /><br /> * State: <input type="text" name="State" value="<?php echo $_POST['State']; ?>" /><br /> * Zip: <input type="text" name="Zip" value="<?php echo $_POST['Zip']; ?>" /><br /> * Interest: <input type="text" name="Interest" value="<?php echo $_POST['Interest']; ?>" /><br /> License: <input type="text" name="License" value="<?php echo $_POST['License']; ?>" /><br /> Business: <input type="text" name="Business" value="<?php echo $_POST['Business']; ?>" /><br /> URL: <input type="text" name="URL" value="<?php echo $_POST['URL']; ?>" /><br /> Comments: <input type="text" name="Comments" value="<?php echo $_POST['Comments']; ?>" /><br /> * Agree: <input type="text" name="Agree" value="<?php echo $_POST['Agree']; ?>" /><br /> <button type="submit">Submit</button><br /><br /> * required fields <input type="hidden" name="submit" value="true" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/194817-continued-email-issue/#findComment-1024963 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.