Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2006
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with mail

    Hi

    I'm new to php and am trying to run the mail command from the following script:

    <?php
    $to = "enquiries@starrygirl.com";
    $subject = "ENQUIRY: $_REQUEST['subject'] ";
    $name = $_REQUEST['name'] ;
    $email = $_REQUEST['email'] ;
    $message = $_REQUEST['message'] ;
    $headers = "From: $email";
    $body = "NAME: $name\n EMAIL: $email\n MESSAGE: $message";
    $sent = mail($to, $subject, $body, $headers) ;
    if($sent)
    {print "Your mail was sent successfully";
    //header ("Location: http:www.starrygirl.com/thankyou.html");
    }
    else
    {print "We encountered an error sending your mail"; }
    ?>

    I'm calling the script from my contact form, however it's falling over with the following compile error:

    Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /homepages/18/d187060535/htdocs/contact.php on line 3

    Does anyone know what this means?

    Thanks for your help
    Starrygirl

  • #2
    New Coder
    Join Date
    Nov 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm no expert, but I would suggest concatenating your strings. For example, rather than this:

    $headers = "From: $email";
    Try this:

    $headers = "From: " . $email;
    I find it useful to echo my variables to find out what exactly is in them. Make sure the value of the variable is coming through.

    echo $headers;
    Currently having a mail() problem myself (not this one of course tho...)

  • #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,023
    Thanks
    2
    Thanked 314 Times in 306 Posts
    It is due to the single-quotes around the index name 'subject' which is then enclosed within the double-quoted string. Change this -
    PHP Code:
    $subject "ENQUIRY: $_REQUEST['subject'] "
    to this -
    PHP Code:
    $subject "ENQUIRY: {$_REQUEST['subject']} "
    or to this -
    PHP Code:
    $subject "ENQUIRY: $_REQUEST[subject] "
    This is about the only inconsistent thing in php that I don't like. PHP has problems figuring out variables with [ ]'s that are within double-quotes.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #4
    New Coder
    Join Date
    Nov 2006
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks guys for your quick responses

    I've changed the line to:

    $subject = "ENQUIRY: $_REQUEST[subject]";

    and that seems to work.

    Was wondering if there is any other way of concatenating strings other than using "."?

    Thanks
    Starrygirl


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •