Romainpetit
Romainpetit

Reputation: 906

Mail Form in PHP : syntax error, unexpected T_VARIABLE

I know this is a very commun issue, but as I didn't forget any semicolon, and I declared all variables at the beginning of the script, I'm wondering why this error still throws.

The code is very simple : EDIT :

if (isset($_POST["email"])) 
{
$name=(isset($_POST["name"])) ? $_POST["name"] : ""; 
$email=(isset($_POST["email"])) ? $_POST["email"] : ""; 
$phone=(isset($_POST["phone"])) ? $_POST["phone"] : ""; 
$ext=(isset($_POST["ext"])) ? $_POST["ext"] : ""; 
$website=(isset($_POST["website"])) ? $_POST["website"] : ""; 
$body=(isset($_POST["body"])) ? $_POST["body"] : ""; 
$to = "[email protected]";
$subject = "Message $name from Infiniscale Website";
$message = "$name sent you a message using the contact form. <br/>";
$message .= "Infos : <br/>";
$message .= "Email : $email <br/>";
$message .= "Phone : $phone <br/>";
$message .= "Ext : $ext <br/>";
$message .= "Website : <a href=\"$website\">$website</a> <br/><br/>";
$message .= "Message: $body <br/>";
$from = "[email protected]";
$headers = "From: " .  $from;
mail($to,$subject,$message,$headers);
return "Attempted Mail Send.";
}
else
{
  return false;
}

The form is sended, and the "Attempted Mail Send." message showed. But I don't receive any email in my mail box, while I know the mail server is working.

Upvotes: 0

Views: 9248

Answers (3)

Msolomonb
Msolomonb

Reputation: 1

I think the header is must be separated by carriage return and new line"\r\n". and your header like this $header="From:".$from . "\r\n" ;

Upvotes: 0

Ariful Islam
Ariful Islam

Reputation: 7675

@Nexerus is correct. Can also use :

$message = "Website : <a href='".$website."'>$website</a> <br/><br/>";

Upvotes: 0

Nexerus
Nexerus

Reputation: 1088

You need to escape the double quotes in your message, so instead of:

$message = "Website : <a href="$website">$website</a> <br/><br/>";

You would need to do

$message = "Website : <a href=\"$website\">$website</a> <br/><br/>";

For all parts of the message that contain double quotes.

Upvotes: 3

Related Questions