View Full Version : Problem with mail

11-23-2006, 09:07 PM

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

$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) ;
{print "Your mail was sent successfully";
//header ("Location: http:www.starrygirl.com/thankyou.html");
{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

11-23-2006, 09:32 PM
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...)

11-23-2006, 09:35 PM
It is due to the single-quotes around the index name 'subject' which is then enclosed within the double-quoted string. Change this -

$subject = "ENQUIRY: $_REQUEST['subject'] ";
to this -

$subject = "ENQUIRY: {$_REQUEST['subject']} ";
or to this -

$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.

11-23-2006, 09:58 PM
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 "."?