...

View Full Version : Problem with mail



starrygirl1980
11-23-2006, 09:07 PM
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

php_leg_end
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...)

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

starrygirl1980
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 "."?

Thanks
Starrygirl



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum