ornclo Posted January 29, 2009 Share Posted January 29, 2009 To Whome May know more about PHP than I... I will be the first to tell you that I get frustrated with PHP (at the moment) because I don't know everything there is to know about it, and I haven't had a chance to really work with it. I am on a time line with a web page that I am creating for my church. I am no Web Master, and a lot of what I have learned is self - taught or looking online to find my answer. This one seems to be a bit more tricky to solve for me. I always seems to simple when I go online, but it never works. So here is my situation. I have a form that I have created that has text fields, radio buttons, and check boxes in it. I have created the php code for this as well. When I hit submit, all I get is my error.html page saying that something in the form is incorrect. So all I asking if someone would be kind enough to look over the code and let me know what I need to do to make it work. Also, ANY additional information that you can give me, would be fantastic. I want to learn more about PHP and how it works and ways to make it simpler. Here is the form: http://www.achurch4life.net/WUcontact.html Here is my code for the php file: <!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=iso-8859-1" /> <title>Emailing Form Data</title> </head> <body> <?php //declaration of variables $EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); $EmailTo = "ornclo@aol.com,ornclo@aol.com"; $Subject = "Women United Contact"; $Name = Trim(stripslashes($_POST['name'])); $Address = Trim(stripslashes($_POST['address'])); $City = Trim(stripslashes($_POST['city'])); $State = Trim(stripslashes($_POST['state'])); $Phone1 = Trim(stripslashes($_POST['phone1'])); $Phone2 = Trim(stripslashes($_POST['phone2'])); $Phone3 = Trim(stripslashes($_POST['phone3'])); $Church = Trim(stripslashes($_POST['visit'])); $About = Trim(stripslashes($_POST['hear'])); $Ask = Trim(stripslashes($_POST['help'])); $Comments = Trim(stripslashes($_POST['comments'])); // validation $validationOK=true; if (Trim($EmailFrom)=="") $validationOK=false; if (Trim($Name)=="") $validationOK=false; if (Trim($Address)=="") $validationOK=false; if (Trim($City)=="") $validationOK=false; if (Trim($State)=="") $validationOK=false; if (Trim($Phone1)=="") $validationOK=false; if (Trim($Phone2)=="") $validationOK=false; if (Trim($Phone3)=="") $validationOK=false; if (Trim($Comments)=="") $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=WUerror.html\">"; exit; } // prepare email body text $Body .= ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Address: "; $Body .= $Address; $Body .= "\n"; $Body .= "City: "; $Body .= $City; $Body .= "\n"; $Body .= "State: "; $Body .= $State; $Body .= "\n"; $Body .= "Phone: "; $Body .= $Phone1; $Body .= "-"; $Body .= $Phone2; $Body .= "-"; $Body .= $Phone3; $Body .= "\n"; $Body .= "Attended Church?: "; $Body .= $Church; $Body .= "\n"; $Body .= "How did they hear about us?: "; $Body .= $About; $Body .= "\n"; $Body .= "What would you like us to do for you?: "; $Body .= $Ask; $Body .= "\n"; $Body .= "Email: "; $Body .= $EmailFrom; $Body .= "\n"; $Body .= "Comments: "; $Body .= $Comments; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=WUok.html\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=Wuerror.html\">"; } php?> </body> </html> Again, any and all help would be greatly appreciated. Thank you in advance. Christopher Quote Link to comment https://forums.phpfreaks.com/topic/143023-solved-php-code-has-me-somewhat-stumped/ Share on other sites More sharing options...
Maq Posted January 29, 2009 Share Posted January 29, 2009 1) Please use tags. 2) What exactly does the error say? 3) Put this as your very first PHP line: ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/143023-solved-php-code-has-me-somewhat-stumped/#findComment-750009 Share on other sites More sharing options...
sasa Posted January 29, 2009 Share Posted January 29, 2009 form field named city doesn't exist in form Quote Link to comment https://forums.phpfreaks.com/topic/143023-solved-php-code-has-me-somewhat-stumped/#findComment-750054 Share on other sites More sharing options...
xangelo Posted January 29, 2009 Share Posted January 29, 2009 Post the form code. Quote Link to comment https://forums.phpfreaks.com/topic/143023-solved-php-code-has-me-somewhat-stumped/#findComment-750071 Share on other sites More sharing options...
Maq Posted January 29, 2009 Share Posted January 29, 2009 form field named city doesn't exist in form Sasa's right, you have 2 "address" fields, you need to change the second one to "city". Address: City: Quote Link to comment https://forums.phpfreaks.com/topic/143023-solved-php-code-has-me-somewhat-stumped/#findComment-750090 Share on other sites More sharing options...
ornclo Posted January 29, 2009 Author Share Posted January 29, 2009 Thank you to both. I have fixed the code. That wasn't the issue. The "error code" is my own error.html screen that comes up. In other words, it doesn't send the form to my email like it is suppost to. Where do I put the part? Or which part are you referring to? I will put that error test code you mentioned in. Quote Link to comment https://forums.phpfreaks.com/topic/143023-solved-php-code-has-me-somewhat-stumped/#findComment-750099 Share on other sites More sharing options...
premiso Posted January 29, 2009 Share Posted January 29, 2009 You put the [ code][ /code] (no initial space) around your code IE: <?php // Your code here ?> Quote Link to comment https://forums.phpfreaks.com/topic/143023-solved-php-code-has-me-somewhat-stumped/#findComment-750101 Share on other sites More sharing options...
ornclo Posted January 29, 2009 Author Share Posted January 29, 2009 <!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=iso-8859-1" /> <title>Emailing Form Data</title> </head> <body> <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); //declaration of variables $EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); $EmailTo = "ornclo@aol.com,ornclo@aol.com"; $Subject = "Women United Contact"; $Name = Trim(stripslashes($_POST['name'])); $Address = Trim(stripslashes($_POST['address'])); $City = Trim(stripslashes($_POST['city'])); $State = Trim(stripslashes($_POST['state'])); $Phone1 = Trim(stripslashes($_POST['phone1'])); $Phone2 = Trim(stripslashes($_POST['phone2'])); $Phone3 = Trim(stripslashes($_POST['phone3'])); $Church = Trim(stripslashes($_POST['visit'])); $About = Trim(stripslashes($_POST['hear'])); $Ask = Trim(stripslashes($_POST['help'])); $Comments = Trim(stripslashes($_POST['comments'])); // validation $validationOK=true; if (Trim($EmailFrom)=="") $validationOK=false; if (Trim($Name)=="") $validationOK=false; if (Trim($Address)=="") $validationOK=false; if (Trim($City)=="") $validationOK=false; if (Trim($State)=="") $validationOK=false; if (Trim($Phone1)=="") $validationOK=false; if (Trim($Phone2)=="") $validationOK=false; if (Trim($Phone3)=="") $validationOK=false; if (Trim($Comments)=="") $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=WUerror.html\">"; exit; } // prepare email body text $Body .= ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Address: "; $Body .= $Address; $Body .= "\n"; $Body .= "City: "; $Body .= $City; $Body .= "\n"; $Body .= "State: "; $Body .= $State; $Body .= "\n"; $Body .= "Phone: "; $Body .= $Phone1; $Body .= "-"; $Body .= $Phone2; $Body .= "-"; $Body .= $Phone3; $Body .= "\n"; $Body .= "Attended Church of God?: "; $Body .= $Church; $Body .= "\n"; $Body .= "How did they hear about us?: "; $Body .= $About; $Body .= "\n"; $Body .= "What would you like us to do for you?: "; $Body .= $Ask; $Body .= "\n"; $Body .= "Email: "; $Body .= $EmailFrom; $Body .= "\n"; $Body .= "Comments: "; $Body .= $Comments; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=WUok.html\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=WUerror.html\">"; } php?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/143023-solved-php-code-has-me-somewhat-stumped/#findComment-750129 Share on other sites More sharing options...
premiso Posted January 29, 2009 Share Posted January 29, 2009 $EmailTo = "ornclo@aol.com,ornclo@aol.com"; Why do you have that duplicated? Are you saying that the email is not being sent? You are also double trimming, I do not think that is needed, also you use Trim, not sure if it matters but it should be trim since php is case sensitive it may matter. Quote Link to comment https://forums.phpfreaks.com/topic/143023-solved-php-code-has-me-somewhat-stumped/#findComment-750134 Share on other sites More sharing options...
ornclo Posted January 29, 2009 Author Share Posted January 29, 2009 Very well. I will take out TRIM and see what happens. As far as the email thing - I was just doing a send to me, as well as a CC. Didn't know if it would work. For now, I will only send to main first. Quote Link to comment https://forums.phpfreaks.com/topic/143023-solved-php-code-has-me-somewhat-stumped/#findComment-750138 Share on other sites More sharing options...
ornclo Posted January 29, 2009 Author Share Posted January 29, 2009 Okay, did as you said and took out all the TRIM. Not to be incrediably stupid, but did I need to take out the "stripsplashes" as well? This is the error I get now: Parse error: parse error, unexpected T_IS_EQUAL in /home/content/a/c/h/achurch4life/html/emailme.php on line 46 Quote Link to comment https://forums.phpfreaks.com/topic/143023-solved-php-code-has-me-somewhat-stumped/#findComment-750141 Share on other sites More sharing options...
premiso Posted January 29, 2009 Share Posted January 29, 2009 I did not mean take out all Trim, just replace the Trim with trim and then take out trim from your if statements. You are already trimming when you assign the variables, no need to trim again. The error you have, chances are it is from removing the trim and forgetting to remove a ). Update that and re-post the updated code so I can see what we are working with. Quote Link to comment https://forums.phpfreaks.com/topic/143023-solved-php-code-has-me-somewhat-stumped/#findComment-750142 Share on other sites More sharing options...
ornclo Posted January 29, 2009 Author Share Posted January 29, 2009 okay, now I'm back to just having the error.html page show up. <!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=iso-8859-1" /> <title>Emailing Form Data</title> </head> <body> <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); //declaration of variables $EmailFrom = trim(stripslashes($_POST['EmailFrom'])); $EmailTo = "ornclo@aol.com"; $Subject = "Women United Contact"; $Name = trim(stripslashes($_POST['name'])); $Address = trim(stripslashes($_POST['address'])); $City = trim(stripslashes($_POST['city'])); $State = trim(stripslashes($_POST['state'])); $Phone1 = trim(stripslashes($_POST['phone1'])); $Phone2 = trim(stripslashes($_POST['phone2'])); $Phone3 = trim(stripslashes($_POST['phone3'])); $Church = trim(stripslashes($_POST['visit'])); $About = trim(stripslashes($_POST['hear'])); $Ask = trim(stripslashes($_POST['help'])); $Comments = trim(stripslashes($_POST['comments'])); // validation $validationOK=true; if (($EmailFrom)=="") $validationOK=false; if (($Name)=="") $validationOK=false; if (($Address)=="") $validationOK=false; if (($City)=="") $validationOK=false; if (($State)=="" ) $validationOK=false; if (($Phone1)=="") $validationOK=false; if (($Phone2)=="") $validationOK=false; if (($Phone3)=="") $validationOK=false; if (($Comments)=="") $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=WUerror.html\">"; exit; } // prepare email body text $Body .= ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Address: "; $Body .= $Address; $Body .= "\n"; $Body .= "City: "; $Body .= $City; $Body .= "\n"; $Body .= "State: "; $Body .= $State; $Body .= "\n"; $Body .= "Phone: "; $Body .= $Phone1; $Body .= "-"; $Body .= $Phone2; $Body .= "-"; $Body .= $Phone3; $Body .= "\n"; $Body .= "Attended Church of God?: "; $Body .= $Church; $Body .= "\n"; $Body .= "How did they hear about us?: "; $Body .= $About; $Body .= "\n"; $Body .= "What would you like us to do for you?: "; $Body .= $Ask; $Body .= "\n"; $Body .= "Email: "; $Body .= $EmailFrom; $Body .= "\n"; $Body .= "Comments: "; $Body .= $Comments; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=WUok.html\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=WUerror.html\">"; } php?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/143023-solved-php-code-has-me-somewhat-stumped/#findComment-750151 Share on other sites More sharing options...
premiso Posted January 29, 2009 Share Posted January 29, 2009 Notice: Undefined index: city in /home/content/a/c/h/achurch4life/html/emailme.php on line 29 When I tried running your form that was the error. Sasa's right, you have 2 "address" fields, you need to change the second one to "city". I believe maq pointed out this error earlier. You need to modify that WUcontact.html and change the above like maq said and it should work. Quote Link to comment https://forums.phpfreaks.com/topic/143023-solved-php-code-has-me-somewhat-stumped/#findComment-750155 Share on other sites More sharing options...
ornclo Posted January 29, 2009 Author Share Posted January 29, 2009 yay!! It worked!! I had that changed, I forgot to throw it out to the server. Sorry. Thank you so much. If I wanted to send that info as a CC to someone, how would I do that?? Quote Link to comment https://forums.phpfreaks.com/topic/143023-solved-php-code-has-me-somewhat-stumped/#findComment-750160 Share on other sites More sharing options...
ornclo Posted January 29, 2009 Author Share Posted January 29, 2009 ah crap. Okay, now - how do I get the radio and checkbox to work. I read at one point about arrays. Do I need to set up an array of some sort so that when the email sends it will send the answer they selected? Quote Link to comment https://forums.phpfreaks.com/topic/143023-solved-php-code-has-me-somewhat-stumped/#findComment-750163 Share on other sites More sharing options...
ornclo Posted January 30, 2009 Author Share Posted January 30, 2009 Well, I have attempted several different things to get the radio and check boxes to show. Could someone help me out with figuring this out?? Quote Link to comment https://forums.phpfreaks.com/topic/143023-solved-php-code-has-me-somewhat-stumped/#findComment-750214 Share on other sites More sharing options...
Maq Posted January 30, 2009 Share Posted January 30, 2009 You may have better luck starting a new thread, with the relevant code. You will get more replies, good luck! Quote Link to comment https://forums.phpfreaks.com/topic/143023-solved-php-code-has-me-somewhat-stumped/#findComment-750609 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.