I've written a php program to send a form by email. The very simple version worked. As soon as I tried to send a more complex form i got this error message:-

Parse error: syntax error, unexpected '=' in E:\domains\s\sheffieldu3a.org.uk\user\htdocs\experiments\sendnmv.php on line 20

Can anyone help? Line 20 is exactly the same format as lines 19, 18 and 17. There is one = on each line. Is this a message which has nothing to do with what it says??!!

    Look for things like missing closing quotes on that line and the preceding lines, or an omitted terminal ";" on the preceding command. (The message means exactly what it says: it found an "=" where it was not expecting one. The "why" it was unexpected is the part you need to figure out. 😉 )

    If you cannot find the problem, post the relevant code up through line 20 here between [noparse]

     . . . 

    [/noparse] tags so we can help.

      I've checked all you suggested but still can't find anything.
      I'm VERY new to this so I could have made more than one mistake!

      Thanks so much for your help
      Here's the full php code:

      <?php
      $to = "webcoordinator@sheffieldu3a.org.uk";
      $subject = "New Members questionnaire";
      $name = $REQUEST['name'] ;
      $email = $
      REQUEST['email'] ;
      $dropin_refreshments = $REQUEST['dropin_refreshments'] ;
      $befriend = $
      REQUEST['befriend'] ;
      $stuffing = $REQUEST['stuffing'] ;
      $seminar = $
      REQUEST['seminar'] ;
      $registration = $REQUEST['registration'] ;
      $steward = $
      REQUEST['steward'] ;
      $outreach = $REQUEST['outreach'] ;
      $ethnic = $
      REQUEST['ethnic'] ;
      $pre-retirement = $REQUEST['pre-retirement'] ;
      $mobility = $
      REQUEST['mobility'] ;
      $writing = $REQUEST['writing'] ;
      $deputy = $
      REQUEST['deputy'] ;
      $new_group = $REQUEST['new_group'] ;
      $research = $
      REQUEST['research'] ;
      $equipment = $_REQUEST['equipment'] ;
      $headers = "From: $email";
      $sent = mail($to, $subject, $name, $dropin_refreshments, $befriend, $stuffing, $seminar, $registration, $steward, $outreach, $ethnic, $pre-retirement, $mobility, $writing, $deputy, $new_group, $research, $equipment, $headers) ;
      if($sent)
      {print "Your form was sent successfully"; }
      else
      {print "We encountered an error sending your form"; }
      ?>

        I would assume it was this variable - $pre-retirement.

        A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.

        So the hyphen in the name would cause a problem.

          $sent = mail($to, $subject, $name, $dropin_refreshments, $befriend, $stuffing, $seminar, $registration, $steward, $outreach, $ethnic, $pre-retirement, $mobility, $writing, $deputy, $new_group, $research, $equipment, $headers) ;

          This can not work.

          [man]mail[/man]
          takes usually only 4 arguments:

          $sent = mail($to, $subject, $message, $headers);

          So, you should make one message out of all those variables.

          <?php
          
          $to = "webcoordinator@sheffieldu3a.org.uk";
          $subject = "New Members questionnaire";
          
          $email = $_REQUEST['email'] ;
          
          // all these should put into one $message
          $name = $_REQUEST['name'] ;
          $dropin_refreshments = $_REQUEST['dropin_refreshments'] ;
          $befriend = $_REQUEST['befriend'] ;
          $stuffing = $_REQUEST['stuffing'] ;
          $seminar = $_REQUEST['seminar'] ;
          $registration = $_REQUEST['registration'] ;
          $steward = $_REQUEST['steward'] ;
          $outreach = $_REQUEST['outreach'] ;
          $ethnic = $_REQUEST['ethnic'] ;
          $pre-retirement = $_REQUEST['pre-retirement'] ;
          $mobility = $_REQUEST['mobility'] ;
          $writing = $_REQUEST['writing'] ;
          $deputy = $_REQUEST['deputy'] ;
          $new_group = $_REQUEST['new_group'] ;
          $research = $_REQUEST['research'] ;
          $equipment = $_REQUEST['equipment'] ;
          
          $headers = "From: $email";
          
          $sent = mail($to, $subject, $message, $headers) ;
          
          if($sent)
          {print "Your form was sent successfully"; }
          else
          {print "We encountered an error sending your form"; }
          
          ?>

            Thank you. I'll try and sort that out and come back if I can't get it to work.

              I've tried a variety of formats but I simply can't work out how to get everything into one $message. The code below was my last useless attempt! What I need it a PHP manual for idiots. Is there such a thing? So far I've relied on what I can find on the 'net - with limited success.

              <?php
              $to = "webcoordinator@sheffieldu3a.org.uk";
              $subject = "New Members questionnaire";
              $message = $_REQUEST['name'] ['email'] ['dropin_refreshments'] ['befriend'] ['stuffing'] ['seminar'] ['registration'] ['steward'] ['outreach' ['ethnic'] ['pre-retirement'] ['mobility'] ['writing'] ['deputy'] ['new_group'] ['research'] ['equipment' ] ;
              $headers = "From: $email";
              $sent = mail($to, $subject, $message, $headers) ;
              if($sent)
              {print "Your form was sent successfully"; }
              else
              {print "We encountered an error sending your form"; }
              ?>

                It's just your $message line that seems to be at fault. The following should work...

                <?php 
                
                $to = "webcoordinator@sheffieldu3a.org.uk"; 
                
                $subject = "New Members questionnaire"; 
                
                $message = $_REQUEST['name'] . "\n\r" . 
                	$_REQUEST['email'] . "\n\r" . 
                	$_REQUEST['dropin_refreshments'] . "\n\r" . 
                	$_REQUEST['befriend'] . "\n\r" . 
                	$_REQUEST['stuffing'] . "\n\r" . 
                	$_REQUEST['seminar'] . "\n\r" . 
                	$_REQUEST['registration'] . "\n\r" . 
                	$_REQUEST['steward'] . "\n\r" . 
                	$_REQUEST['outreach'] . "\n\r" . 
                	$_REQUEST['ethnic'] . "\n\r" . 
                	$_REQUEST['pre-retirement'] . "\n\r" . 
                	$_REQUEST['mobility'] . "\n\r" . 
                	$_REQUEST['writing'] . "\n\r" . 
                	$_REQUEST['deputy'] . "\n\r" . 
                	$_REQUEST['new_group'] . "\n\r" . 
                	$_REQUEST['research'] . "\n\r" . 
                	$_REQUEST['equipment'];
                
                $headers = "From: $email"; 
                
                $sent = mail($to, $subject, $message, $headers) ; 
                
                if($sent) {
                print "Your form was sent successfully";
                } else {
                print "We encountered an error sending your form";
                }
                ?>

                  First let us agree to change $pre-retirement = $REQUEST['pre-retirement'] ;
                  as pointed out in a previous post.
                  Both in this page AND in your form we change it to:
                  $pre_retirement = $
                  REQUEST['pre_retirement'] ;

                  I have put "\n"(newline) at end of each line in message.
                  So each REQUEST data comes at a new line of email.

                  Hope this will work.
                  But we never know before we try 🙂

                  <?php
                  
                  $to = "webcoordinator@sheffieldu3a.org.uk";
                  $subject = "New Members questionnaire";
                  
                  $email = $_REQUEST['email'] ;
                  
                  $message =
                  'name = '        .$_REQUEST['name']."\n".
                  'dropin_refreshments = '.$_REQUEST['dropin_refreshments']."\n".
                  'befriend = '    .$_REQUEST['befriend']."\n".
                  'stuffing = '    .$_REQUEST['stuffing']."\n".
                  'seminar = '     .$_REQUEST['seminar']."\n".
                  'registration = '.$_REQUEST['registration']."\n".
                  'steward = '     .$_REQUEST['steward']."\n".
                  'outreach = '    .$_REQUEST['outreach']."\n".
                  'ethnic = '      .$_REQUEST['ethnic']."\n".
                  'pre_retirement = '.$_REQUEST['pre_retirement']."\n".
                  'mobility = '    .$_REQUEST['mobility']."\n".
                  'writing = '     .$_REQUEST['writing']."\n".
                  'deputy = '      .$_REQUEST['deputy']."\n".
                  'new_group = '   .$_REQUEST['new_group']."\n".
                  'research = '    .$_REQUEST['research']."\n".
                  'equipment = '   .$_REQUEST['equipment']."\n";
                  
                  $headers = "From: $email";
                  
                  $sent = mail($to, $subject, $message, $headers) ;
                  
                  if($sent)
                  {print "Your form was sent successfully"; }
                  else
                  {print "We encountered an error sending your form"; }
                  
                  ?> 

                    This seems to have sorted out the original problem. Thank you. BUT I now have the following error messages. Any Suggestions?

                    Notice: Undefined index: email in E:\domains\s\sheffieldu3a.org.uk\user\htdocs\experiments\sendnmv.php on line 12

                    Notice: Undefined index: name in E:\domains\s\sheffieldu3a.org.uk\user\htdocs\experiments\sendnmv.php on line 15

                    Notice: Undefined index: pre_retirement in E:\domains\s\sheffieldu3a.org.uk\user\htdocs\experiments\sendnmv.php on line 24

                    Warning: mail() [function.mail]: SMTP server response: 554 <webcoordinator@sheffieldu3a.org.uk>: Recipient address rejected: Relay access denied in E:\domains\s\sheffieldu3a.org.uk\user\htdocs\experiments\sendnmv.php on line 34
                    We encountered an error sending your form

                      Thank you everyone who helped.
                      I seem to have got it working!! What arelief!

                        Write a Reply...