By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,101 Members | 1,394 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,101 IT Pros & Developers. It's quick & easy.

how do you fix Parse error: syntax error, unexpected $end in

P: 3
Hello everyone, I'm new to php and to forums so please be gentle.

I'm trying to create my first form and php script for a website that will allow the user to send their info to me in an email. Then the user will get a response that their info was recieved.

I'm getting this error code:
Parse error: syntax error, unexpected $end in /home/tgoode/prospectingtreasures/contactus.php on line 77

This is the php I have:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Underconstruction Page</title>
  6. </head>
  7.  
  8. <body>
  9. <?php
  10. $to = $_REQUEST['sendto'];   // are these 1st 2 varaible correct?
  11. $from = $_REQUEST['email'];
  12. $name = $_REQUEST['name'];
  13. $address1 = $_REQUEST['address1'];
  14. $address2 = $_REQUEST['address2'];
  15. $city = $_REQUEST['city'];
  16. $county = $_REQUEST['county'];
  17. $state = $_REQUEST['state'];
  18. $zip = $_REQUEST['zip'];
  19. $phone = $_REQUEST['phone'];
  20. $fax = $_REQUEST['fax'];
  21. $webaddress = $_REQUEST['webaddress'];
  22. $email = $_REQUEST['email'];
  23. $messages = $_REQUEST['messages'];
  24. $headers = "From: $from";
  25. $subject = "Web Contact Data";
  26.  
  27. $fields = array();
  28.     $fields{"name"} = "name";
  29.     $fields{"address1"} = "address1";
  30.     $fields{"address2"} = "address2"; // not required
  31.     $fields{"city"} = "city";
  32.     $fields{"county"} = "county";
  33.     $fields{"state"} = "state";
  34.     $fields{"zip"} = "zip";
  35.     $fields{"phone"} = "phone"; // not required
  36.     $fields{"fax"} = "fax"; // not required
  37.     $fields{"webaddress"} = "webaddress";
  38.     $fields{"email"} = "email";
  39.     $fields{"messages"} = "messages"; // not required
  40.  
  41. //what does this line do?
  42. $body = "We have recieved the following information:\n\n"; foreach($fields as $a => $b) { $body .= sprintf("%20s: $s\n",$b,$_REQUEST[$a]);}
  43.  
  44. $headers2 = "From: prospectingtreasures.com";
  45. $subject2 = "Thank you for contacting us";
  46. $autoreply = "Thank you for contacting us " . name . ". You should here from us usally within 48 hours. If you have more questions or requests, please email us at prospectingtreasures@gmail.com/";
  47.  
  48. if($from =='') {print "You have not entered an email, please enter";}
  49. else {
  50. if($name == '') {print "You have not entered a name or company name, please go back and enter a name";}
  51. else {
  52. if($address1 == '') {print "You forgot to enter a street address, please go back and enter an address";}
  53. else {
  54. if($city == '') {print "You forgot to enter your city, please go back and enter your city";}
  55. else {
  56. if($county == '') {print "You forgot to enter your county, please go back and enter your county";}
  57. else {
  58. if($state == '') {print "You forgot to enter your state, please go back and enter your state";}
  59. else {
  60. if($zip == '') {print "you forgot to enter your zipcode, please go back and enter yor zipcode";}
  61. else {
  62. if($webaddress == '') {print " You forgot to give us your web address, please enter you web address";}
  63. else {
  64. if($email == '') {print "You have not entered an email address, please go back and enter your email address";}
  65.  
  66. $send = mail($to, $subject, $body, $headers);    
  67. $send2 = mail($from, $subject2, $autoreply, $headers2);
  68. if($send)
  69. {header( " Location: http://www.prospectingtreasures.com/tgoode/thankyou.php" );}  //what does this line do?
  70. else
  71. {print "We encountered an error sending your mail, please notify webmaster@YourCompany.com";}
  72. }//where is th open?
  73. }//where is th open?}
  74.  
  75. //been lookin at this all day for missing brackets and comma and such, wondering if its something else?
  76.  
  77. ?>
  78. </body>
  79. </html>
  80.  
thank you in advance for the help
please help me get started in understanding
Nov 1 '11 #1

✓ answered by omerbutt

hi togoode
here is the fixed version , the constraints check if else where you are checking for empty email and from field, you were missing approx 9 closing braces :S , and you would have figured it out if you had right code indent , thats why it is important look at the code now.
Expand|Select|Wrap|Line Numbers
  1.     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2.     <html xmlns="http://www.w3.org/1999/xhtml">
  3.     <head>
  4.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5.     <title>Underconstruction Page</title>
  6.     </head>
  7.  
  8.     <body>
  9.     <?php
  10.     $to = $_REQUEST['sendto'];   // are these 1st 2 varaible correct?
  11.     $from = $_REQUEST['email'];
  12.     $name = $_REQUEST['name'];
  13.     $address1 = $_REQUEST['address1'];
  14.     $address2 = $_REQUEST['address2'];
  15.     $city = $_REQUEST['city'];
  16.     $county = $_REQUEST['county'];
  17.     $state = $_REQUEST['state'];
  18.     $zip = $_REQUEST['zip'];
  19.     $phone = $_REQUEST['phone'];
  20.     $fax = $_REQUEST['fax'];
  21.     $webaddress = $_REQUEST['webaddress'];
  22.     $email = $_REQUEST['email'];
  23.     $messages = $_REQUEST['messages'];
  24.     $headers = "From: $from";
  25.     $subject = "Web Contact Data";
  26.  
  27.     $fields = array();
  28.     $fields{"name"} = "name";
  29.     $fields{"address1"} = "address1";
  30.     $fields{"address2"} = "address2"; // not required
  31.     $fields{"city"} = "city";
  32.     $fields{"county"} = "county";
  33.     $fields{"state"} = "state";
  34.     $fields{"zip"} = "zip";
  35.     $fields{"phone"} = "phone"; // not required
  36.     $fields{"fax"} = "fax"; // not required
  37.     $fields{"webaddress"} = "webaddress";
  38.     $fields{"email"} = "email";
  39.     $fields{"messages"} = "messages"; // not required
  40.  
  41.     //what does this line do?
  42.     $body = "We have recieved the following information:\n\n"; foreach($fields as $a => $b) { $body .= sprintf("%20s: $s\n",$b,$_REQUEST[$a]);}
  43.  
  44.     $headers2 = "From: prospectingtreasures.com";
  45.     $subject2 = "Thank you for contacting us";
  46.     $autoreply = "Thank you for contacting us " . $name . ". 
  47.     You should here from us usally within 48 hours. If you have more questions or requests, please email us at prospectingtreasures@gmail.com/";
  48.  
  49.     if($from =='') {
  50.         print "You have not entered an email, please enter";
  51.     }else {
  52.         if($name == '') {
  53.             print "You have not entered a name or company name, please go back and enter a name";
  54.         }else {
  55.             if($address1 == '') {print "You forgot to enter a street address, please go back and enter an address";
  56.             }else {
  57.                 if($city == '') {print "You forgot to enter your city, please go back and enter your city";
  58.                 }else {
  59.                     if($county == '') {print "You forgot to enter your county, please go back and enter your county";
  60.                     }else {
  61.                         if($state == '') {print "You forgot to enter your state, please go back and enter your state";
  62.                         }else {
  63.                             if($zip == '') {print "you forgot to enter your zipcode, please go back and enter yor zipcode";
  64.                             }else {
  65.                                 if($webaddress == '') {
  66.                                     print " You forgot to give us your web address, please enter you web address";
  67.                                 }else {
  68.                                     if($email == '') {
  69.                                         print "You have not entered an email address, please go back and enter your email address";
  70.                                     }
  71.                                 }
  72.                             }
  73.                         }
  74.                     }
  75.                 }
  76.             }
  77.         }
  78.     }
  79.  
  80.     $send = mail($to, $subject, $body, $headers);    
  81.     $send2 = mail($from, $subject2, $autoreply, $headers2);
  82.     if($send){
  83.         header( " Location: http://www.prospectingtreasures.com/tgoode/thankyou.php" );
  84.     }else{
  85.         print "We encountered an error sending your mail, please notify webmaster@YourCompany.com";
  86.     }
  87.  
  88.     ?>
  89.     </body>
  90.     </html>
  91.  

Share this Question
Share on Google+
9 Replies


Dormilich
Expert Mod 5K+
P: 8,639
//been lookin at this all day for missing brackets and comma and such, wondering if its something else?
Iím not sure how you counted the braces, Iíve found at least 6 missing closing ones.

and line 27 - 39 are way off, too. you should read up on how to define an array sensibly.
Nov 1 '11 #2

omerbutt
100+
P: 638
hi togoode
here is the fixed version , the constraints check if else where you are checking for empty email and from field, you were missing approx 9 closing braces :S , and you would have figured it out if you had right code indent , thats why it is important look at the code now.
Expand|Select|Wrap|Line Numbers
  1.     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2.     <html xmlns="http://www.w3.org/1999/xhtml">
  3.     <head>
  4.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5.     <title>Underconstruction Page</title>
  6.     </head>
  7.  
  8.     <body>
  9.     <?php
  10.     $to = $_REQUEST['sendto'];   // are these 1st 2 varaible correct?
  11.     $from = $_REQUEST['email'];
  12.     $name = $_REQUEST['name'];
  13.     $address1 = $_REQUEST['address1'];
  14.     $address2 = $_REQUEST['address2'];
  15.     $city = $_REQUEST['city'];
  16.     $county = $_REQUEST['county'];
  17.     $state = $_REQUEST['state'];
  18.     $zip = $_REQUEST['zip'];
  19.     $phone = $_REQUEST['phone'];
  20.     $fax = $_REQUEST['fax'];
  21.     $webaddress = $_REQUEST['webaddress'];
  22.     $email = $_REQUEST['email'];
  23.     $messages = $_REQUEST['messages'];
  24.     $headers = "From: $from";
  25.     $subject = "Web Contact Data";
  26.  
  27.     $fields = array();
  28.     $fields{"name"} = "name";
  29.     $fields{"address1"} = "address1";
  30.     $fields{"address2"} = "address2"; // not required
  31.     $fields{"city"} = "city";
  32.     $fields{"county"} = "county";
  33.     $fields{"state"} = "state";
  34.     $fields{"zip"} = "zip";
  35.     $fields{"phone"} = "phone"; // not required
  36.     $fields{"fax"} = "fax"; // not required
  37.     $fields{"webaddress"} = "webaddress";
  38.     $fields{"email"} = "email";
  39.     $fields{"messages"} = "messages"; // not required
  40.  
  41.     //what does this line do?
  42.     $body = "We have recieved the following information:\n\n"; foreach($fields as $a => $b) { $body .= sprintf("%20s: $s\n",$b,$_REQUEST[$a]);}
  43.  
  44.     $headers2 = "From: prospectingtreasures.com";
  45.     $subject2 = "Thank you for contacting us";
  46.     $autoreply = "Thank you for contacting us " . $name . ". 
  47.     You should here from us usally within 48 hours. If you have more questions or requests, please email us at prospectingtreasures@gmail.com/";
  48.  
  49.     if($from =='') {
  50.         print "You have not entered an email, please enter";
  51.     }else {
  52.         if($name == '') {
  53.             print "You have not entered a name or company name, please go back and enter a name";
  54.         }else {
  55.             if($address1 == '') {print "You forgot to enter a street address, please go back and enter an address";
  56.             }else {
  57.                 if($city == '') {print "You forgot to enter your city, please go back and enter your city";
  58.                 }else {
  59.                     if($county == '') {print "You forgot to enter your county, please go back and enter your county";
  60.                     }else {
  61.                         if($state == '') {print "You forgot to enter your state, please go back and enter your state";
  62.                         }else {
  63.                             if($zip == '') {print "you forgot to enter your zipcode, please go back and enter yor zipcode";
  64.                             }else {
  65.                                 if($webaddress == '') {
  66.                                     print " You forgot to give us your web address, please enter you web address";
  67.                                 }else {
  68.                                     if($email == '') {
  69.                                         print "You have not entered an email address, please go back and enter your email address";
  70.                                     }
  71.                                 }
  72.                             }
  73.                         }
  74.                     }
  75.                 }
  76.             }
  77.         }
  78.     }
  79.  
  80.     $send = mail($to, $subject, $body, $headers);    
  81.     $send2 = mail($from, $subject2, $autoreply, $headers2);
  82.     if($send){
  83.         header( " Location: http://www.prospectingtreasures.com/tgoode/thankyou.php" );
  84.     }else{
  85.         print "We encountered an error sending your mail, please notify webmaster@YourCompany.com";
  86.     }
  87.  
  88.     ?>
  89.     </body>
  90.     </html>
  91.  
Nov 2 '11 #3

Dormilich
Expert Mod 5K+
P: 8,639
why using else { if () {} } when you can use elseif () {} ?

how to define an array:
Expand|Select|Wrap|Line Numbers
  1. $fields = array(
  2.     "name" => "name",
  3.     "address" => "address",
  4.     "zip" => "zip"
  5. );
Nov 2 '11 #4

omerbutt
100+
P: 638
yes ,
i agree with dormilich in case of the ifelse as the current method is really old and confusing
regards,
Omer Aslam
Nov 2 '11 #5

P: 3
Thanks much omerbutt and Dormilich. I got it going but I need to touch it up a liitle. It gets real hard to see all them brackets. I only started PHP bout 3 weeks ago so I'm still trying to get the syntax. I will have to study more on the arrays Dormalich. Thanks again. Keep an eye out, I ask alot of questions. :)
Nov 2 '11 #6

Dormilich
Expert Mod 5K+
P: 8,639
the brackets are no problem if you indent them properly.
Nov 3 '11 #7

P: 3
I see that Dreamweaver's IDE will make the correct indentions if I were to let it. I had tabbed them all back so could see the code better. Guess I shouldn't do that. Thanks buddy.
Nov 3 '11 #8

Dormilich
Expert Mod 5K+
P: 8,639
there is certainly a setting that lets you control, how wide a tab is (e.g. 2, 4 or 8 spaces)

if you need that much nesting, there might also be something wrong with the programme logic.
Nov 3 '11 #9

omerbutt
100+
P: 638
if you need that much nesting, there might also be something wrong with the programme logic.
:D...hahah .....somehow right,
Omer Aslam
Nov 10 '11 #10

Post your reply

Sign in to post your reply or Sign up for a free account.