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

Parse Error

P: 1
I have a pretty limited knowledge of PHP.

My scenario is:

I want one form to have two (2) submit buttons. I want one button to submit an email to a specific address then redirect to a page, and I want the second one to submit to the same email, then redirect to a different page. I've downloaded some code, so I can't take credit for it, but I'm trying to use my basic knowledge to create and IF and ELSE IF. Right now, I'm just trying to get the code to work at all, so I have the form simply submitting the form data to an email address based on the button that was clicked.

I get the following parse error:

Parse error: syntax error, unexpected T_ELSE in /home/salamone/public_html/sendeail.php on line 65

Code:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2.  
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Sendemail Script</title>
  7. </head>
  8. <body>
  9.  
  10. <?php
  11.  
  12.  
  13.  
  14.  
  15.  
  16. $ip = $_POST['ip'];
  17. $httpref = $_POST['httpref'];
  18. $httpagent = $_POST['httpagent'];
  19. $visitor = $_POST['visitor'];
  20. $visitormail = $_POST['visitormail'];
  21. $notes = $_POST['notes'];
  22. $attn = $_POST['attn'];
  23.  
  24.  
  25. if (eregi('http:', $notes)) {
  26. die ("Do NOT try that! ! ");
  27. }
  28. if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
  29. {
  30. echo "<h2>Use Back - Enter valid e-mail</h2>\n";
  31. $badinput = "<h2>Feedback was NOT submitted</h2>\n";
  32. echo $badinput;
  33. die ("Go back! ! ");
  34. }
  35.  
  36. if(empty($visitor) || empty($visitormail) || empty($notes )) {
  37. echo "<h2>Use Back - fill in all fields</h2>\n";
  38. die ("Use back! ! ");
  39. }
  40.  
  41. if(isset($_POST["sendmail"]) && trim($_POST["sendmail"])!=='') {
  42.  
  43. $todayis = date("l, F j, Y, g:i a") ;
  44.  
  45. $attn = $attn ;
  46. $subject = $attn;
  47.  
  48. $notes = stripcslashes($notes);
  49.  
  50. $message = " $todayis [EST] \n
  51. Attention: $attn \n
  52. Message: $notes \n
  53. From: $visitor ($visitormail)\n
  54. Additional Info : IP = $ip \n
  55. Browser Info: $httpagent \n
  56. Referral : $httpref \n
  57. ";
  58.  
  59. $from = "From: $visitormail\r\n";
  60.  
  61.  
  62. mail("test1@myemail.com", $subject, $message, $from)
  63.  
  64.  
  65. else if(isset($_POST["sendmail2"]) && trim($_POST["sendmail2"])!=='') {
  66. $todayis = date("l, F j, Y, g:i a") ;
  67.  
  68. $attn = $attn ;
  69. $subject = $attn;
  70.  
  71. $notes = stripcslashes($notes);
  72.  
  73. $message = " $todayis [EST] \n
  74. Attention: $attn \n
  75. Message: $notes \n
  76. From: $visitor ($visitormail)\n
  77. Additional Info : IP = $ip \n
  78. Browser Info: $httpagent \n
  79. Referral : $httpref \n
  80. ";
  81.  
  82. $from = "From: $visitormail\r\n";
  83.  
  84.  
  85. mail("test2@myemail.com", $subject, $message, $from)}
  86.  
  87. ?>
  88. </body>
  89. </html>
  90.  
If I am missing something? Thanks in advance!
Sep 17 '09 #1
Share this Question
Share on Google+
4 Replies


TheServant
Expert 100+
P: 1,168
Main reason:
You have not closed your if statement with curly brackets. Should be like:
Expand|Select|Wrap|Line Numbers
  1. if (x=1) {
  2. //do something
  3. }
  4. elseif (x=2) {
  5. //do something else
  6. }
  7. else {
  8. //do yet another thing
  9. }
Hope that helps. Welcome to Bytes.
Sep 17 '09 #2

Atli
Expert 5K+
P: 5,058
Hey. Welcome to Bytes!

I see 2 errors there.

On lines #62 and #85 you are missing the semi-colon (;) to end the line.

And, before the "else if " on line #65, you are missing the } to close the if preceding it.

An if structure should look like:
Expand|Select|Wrap|Line Numbers
  1. if {
  2.   // statementes
  3. }
  4. else if {
  5.   // statements
  6. }
Yours is like this:
Expand|Select|Wrap|Line Numbers
  1. if {
  2.   // statementes
  3. else if {
  4.   // statements
  5. }
Sep 17 '09 #3

Atli
Expert 5K+
P: 5,058
@TheServant
Actually, both work in the typical curly-braces structure.
(See elseif/else if - PHP manual)
Sep 17 '09 #4

TheServant
Expert 100+
P: 1,168
@Atli
Point taken. Thanks. And well done with the ";" pick-up ;)
Sep 17 '09 #5

Post your reply

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