How can I resolve my form mail script error?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HarryAgy
    New Member
    • Jan 2010
    • 1

    How can I resolve my form mail script error?

    This is the error message i got: (Parse error: syntax error, unexpected T_VARIABLE in /home/vocroyal/public_html/sendmail.php on line 12)

    This is the full script detail:
    Code:
    <?php
      $fullname = $_REQUEST['fullname'] ;
      $company = $_REQUEST['company'] ;
      $address = $_REQUEST['address'] ;
      $line1 = $_REQUEST['line1'] ;
      $city = $_REQUEST['city'] ;
      $country = $_REQUEST['country'] ;
      $email = $_REQUEST['email'] ;
      $phone = $_REQUEST['phone'] ;
      $product = $_REQUEST['product'] ;
      $order = $_REQUEST['order'] 
      $comments = $_REQUEST['comments'] ;
    
      mail( "sales@vocroyalresources.com","Product Order",$fullname,  $company, $address,  $line1, $city, $country, $email, $phone, $product,  $order, $comments, "From: $email");
     echo "<h2>Thank you for sending your order. We will get back to you!<p>Please Use the Back Button on the Left side of your Browser to Continue.</p></h2>";
    ?>
  • dgreenhouse
    Recognized Expert Contributor
    • May 2008
    • 250

    #2
    Correction again:
    You forgot the semicolon at the end of: $order = $_REQUEST['order'] on line 11
    (ergo the - unexpected T_VARIABLE ... on line 12)
    see: http://onlamp.com/pub/a/php/2004/08/...uggingPHP.html


    Correction: You should test for the existence of the $_REQUEST vars before assigning them to local vars, but the mail command; as stated, is wrong. I'll post a generic $_REQUEST assignment function soon...

    There's nothing wrong with the code that transfers the $_REQUEST vars to local vars; other than being totally in-secure, but the mail(...) command is absolutely incorrect.

    The mail command should be used like this:
    Code:
    $to      = 'nobody@example.com';
    $subject = 'the subject';
    $message = 'hello';
    $headers = 'From: webmaster@example.com' . "\r\n" .
       'Reply-To: webmaster@example.com' . "\r\n" .
       'X-Mailer: PHP/' . phpversion();
    
    mail($to, $subject, $message, $headers);

    Comment

    • dgreenhouse
      Recognized Expert Contributor
      • May 2008
      • 250

      #3
      Here's a generic $_REQUEST assignment function that's the beginning of a more robust user input validation routine.

      Code:
      // List of expected user input variables/values
      $expected = array('fullname','company','address');
      
      /**
       Step through the $_REQUEST array looking for expected input
       and only assign to local variables if it's set.
       If the expected variable is empty in the $_REQUEST array,
       set the local variable to NULL
       */
      foreach ($expected as $key) {
        if ( !empty( $_REQUEST[ $key ] ) ) {
          ${$key} = $_REQUEST[ $key ];
        } else {
          ${$key} = NULL;
        }
      }

      Comment

      • dgreenhouse
        Recognized Expert Contributor
        • May 2008
        • 250

        #4
        Note: I didn't mean to mess-up any newbies by using the $_REQUEST global in the example I provided above.

        Normally you should use the appropriate $_GET or $_POST variables versus the $_REQUEST variable. The $_REQUEST variable also includes the $_COOKIE variable by default and could obviously cause clashes if you have variables with the same names in any of the other global variables.

        As per this post: http://www.php.net/manual/en/reserve...uest.php#84527, you might want to use a switch block to determine the request method.

        You'll notice that the code referenced in this posting is getting a reference to the targeted global array so the only cost is a memory location for the pointer.

        Comment

        Working...