mj1224 Posted September 5, 2008 Share Posted September 5, 2008 I am not a php person, and I get a pase error : Parse error: parse error in www.mywebsite/contact.php on line 35 Line 35 is the last line of that file. I copied script from a code helper and loaded it but get that error when I fill in my form to submit it by email. What did I do wrong? Quote Link to comment Share on other sites More sharing options...
stuffradio Posted September 5, 2008 Share Posted September 5, 2008 We don't know without any code. Quote Link to comment Share on other sites More sharing options...
mj1224 Posted September 5, 2008 Author Share Posted September 5, 2008 Here is the html for my form: <form name="gsginfo" method="post" action="contact.php"> <h3>Would you like more information?</h3> <p> Name: <input name="name" type="text" id="name" size="40" maxlength="40"> <span class="style3">*</span></p> <p>Address: <input name="address" type="text" id="address" size="60" maxlength="60"> </p> <p>City: <input name="city" type="text" id="city" size="25" maxlength="25"> </p> <p>State: <input name="state" type="text" id="state" size="2" maxlength="2"> </p> <p>Zip: <input name="zip" type="text" id="zip" size="10" maxlength="10"> </p> <p>Phone: <input name="phone" type="text" id="phone" size="15" maxlength="15"> <span class="style3">*<span class="style2">In case we have problems with your email.</span></span></p> <p>Email: <input name="email" type="text" id="email" size="30" maxlength="30"> <span class="style3">*</span></p> <p>Questions/Comments: <textarea name="comments" id="comments" cols="45" rows="5"></textarea> </p> <p> </p> <p> <input name="submit" type="submit" id="submit"> </p> </form> and here is my php: <?php $to = "tadams@forestry.state.sc.us"; $from = $_REQUEST['email'] ; $name = $_REQUEST['name'] ; $header = "From: $from"; $subject = "Grow Some Green" ; $fields = array(); $fields{"name"} = "Name"; $fields{"address"} = "Address"; $fields{"city"} = "City"; $fields{"state"} = "State"; $fields{"zip"} = "Zip"; $fields{"phone"} = "Phone"; $fields{"email"} = "Email"; $fields{"comments"} = "Comments-Questions"; $body = "We have received the following information:"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $autoreply = "Thank you for your interest in Grow Some Green. Someone will contact you shortly. If you have any more questions, please consult our website at www.growsomegreen.com"; if($email == '') {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 { if($phone == '') {print "You have not entered a phone number to get in touch with you in case we have problems replying to your email, please go back and try again";} else { $send = mail($to, $subject, $body, $header); if($send) {header( "Location: http://www.state.sc.us/forest/thankyou.htm" );} else {print "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; } ?> What did I do wrong? Any help or suggestions wold be welcomed. I don't know php. Quote Link to comment Share on other sites More sharing options...
stuffradio Posted September 5, 2008 Share Posted September 5, 2008 Is there a space after '?>' or is there a blank line after it? Quote Link to comment Share on other sites More sharing options...
mj1224 Posted September 5, 2008 Author Share Posted September 5, 2008 no space or blank line. Quote Link to comment Share on other sites More sharing options...
revraz Posted September 5, 2008 Share Posted September 5, 2008 You need to learn to indent Where is the closing bracket for this else? else { $send = mail($to, $subject, $body, $header); if($send) {header( "Location: http://www.state.sc.us/forest/thankyou.htm" );} else {print "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; } And you use { } incorrectly throughout all your code. Quote Link to comment Share on other sites More sharing options...
mj1224 Posted September 8, 2008 Author Share Posted September 8, 2008 I copied the code from another php helper website and just pasted it in. I added a closing bracket qand it still doesn't work. What difference does indenting make? i don't know php, I'm sorry. just trying to make a simple form be emailed from our website. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted September 8, 2008 Share Posted September 8, 2008 Here I fixed up your code, making it neater. Should work now: <?php $to = "tadams@forestry.state.sc.us"; $from = $_REQUEST['email'] ; $name = $_REQUEST['name'] ; $header = "From: $from"; $subject = "Grow Some Green" ; $fields = array(); $fields["name"] = "Name"; $fields["address"] = "Address"; $fields["city"] = "City"; $fields["state"] = "State"; $fields["zip"] = "Zip"; $fields["phone"] = "Phone"; $fields["email"] = "Email"; $fields["comments"] = "Comments-Questions"; $body = "We have received the following information:"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $autoreply = <<<html Thank you for your interest in Grow Some Green. Someone will contact you shortly. If you have any more questions, please consult our website at www.growsomegreen.com html; if($email == ''){ print "You have not entered an email, please go back and try again"; }elseif($name == ''){ print "You have not entered a name, please go back and try again"; }elseif($phone == ''){ print "You have not entered a phone number to get in touch with you in case we have problems replying to your email, please go back and try again"; }else{ $send = mail($to, $subject, $body, $header); if($send){ header( "Location: http://www.state.sc.us/forest/thankyou.htm" ); }else{ print "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; } } ?> The only difference indenting will make is the readability of your code. Good indentation is critical for good code, IMO. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted September 8, 2008 Share Posted September 8, 2008 If you copied this code from another PHP helper site, why don't you ask the question there? This code has problems as written. Also, using a piece of code with out knowing the language it's written in can be quite dangerous (IMHO). Indenting doesn't make a difference when the code runs, it makes a difference when humans try to read it. This code was written using some very old methods. It assumes that register_globals is enabled, which hasn't been the case in many years. It uses the archaic method of using "{ }" for indexing. And uses the $_REQUEST array instead of the $_POST array. Ken Quote Link to comment Share on other sites More sharing options...
mj1224 Posted September 8, 2008 Author Share Posted September 8, 2008 Thanks for your help. I replced my code with what you wrote and I don't get teh parse error. i get you didn't enter a valid email - even though i did when I tried it. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted September 8, 2008 Share Posted September 8, 2008 As kenrbnsn said, they use outdated methods that should not be used anymore. Perhaps google for a better email script. 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.