Forum Moderators: coopster
PHP Parse error: syntax error, unexpected T_VARIABLE in /home/user/www/example.com/email.php on line 31
Lines before and after line 31 are below:
29 $phone = $_POST['phone'];
30 $subject = "Inquiry from your website";
31 $message .= "<br><br>Name: $name<br>Phone: $phone<br>Best time to contact: $contact
32 <br>Injuries: ".$injuries."</html>";
33
34 $my_headers = "MIME-Version: 1.0\r\n";
35 $my_headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
36 $my_headers .= "From: $name ($from)\r\n";
Was hosting on windows but now on linux.
Things that i think are wrong and removed to no avail:
The . after $message
the .before and after $injuries
the \r on the 3 my_header lines
the /html
I was writing new script but it references a couple of .htm pages so thought it would be easier to modify this script.
Any help would be much appreciated.
Thanks
[edited by: eelixduppy at 4:11 pm (utc) on Mar. 26, 2007]
[edit reason] exemplified error [/edit]
$message .= "<br><br>Name: $name<br>Phone: $phone<br>Best time to contact: $contact
<br>Injuries: ".$injuries."</html>";
with this"
$message .= "<br><br>Name: $name<br>Phone: $phone<br>Best time to contact: $contact<br>Injuries: ".$injuries."</html>"; #without the line break
See if that fixes it; it might.
No, you do not need a semicolon after <br>.
$message instead of setting it equal to it. I'm not sure if you have message defined before those lines? If not, you should remove that period:
$message = "<br><br>Name: $name<br>Phone: $phone<br>Best time to contact: $contact<br>Injuries: ".$injuries."</html>";
Other than that, I do not know; everything looks good. Are you positive those are the correct lines in the file? Sometimes it can be tricky ;)
Oh, and by the way - Welcome to WebmasterWorld! :)
I'm attaching the entire .php script to see if it's somewhere else. Error log says line 31. When you submit it calls the false function at the end resulting in the message mail could not be sent.
Thanks again
<?php
// Read POST request params into global vars
function valid_email($address)
{
// check an email address is possibly valid
if (ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $address))
return true;
else
return false;
}
$name = $_POST['name'];
$contact = $_POST['contact'];
$to = "contact@domain.com";
$from = $_POST['email'];
$injuries = $_POST['injuries'];
if (!valid_email($from))
{
include("header.htm");
echo "Please provide us with a valid email address. ";
echo "<br><br><a href=index.htm>Back to home</a>";
include("footer.htm");
exit;
}
$phone = $_POST['phone'];
$subject = "Inquiry from your website";
$message = "<br><br>Name: $name<br>Phone: $phone<br>Best time to contact: $contact <br>Injuries: ".$injuries."</html>";
$my_headers = "MIME-Version: 1.0\r\n";
$my_headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$my_headers .= "From: $name ($from)\r\n";
$new_message = html_entity_decode($message);
if (!$from ¦¦!$name ¦¦!$phone)
{
include("header.htm");
echo "Please fill in all fields.";
echo "<br><br><a href=index.htm>Back to home</a>";
include("footer.htm");
}
else {
$mess = "Thank you for submitting an inquiry for legal help with *******. Your information will be reviewed and you will be contacted shortly.";
mail($from, "Auto-response from *****", $mess, "***************");
// Send the message
$ok = @mail($to, $subject, $new_message , $my_headers);
if ($ok) {
header("Location: confirm.htm");
} else {
echo "<p>Mail could not be sent!</p>";
}
>> Error log says line 31
Are you sure this error keeps coming up each time you run the script? Maybe someone already fixed it and it's still in the error log?
the last test is, you can change $message to:
$message = "<br><br>Name: $name<br>Phone: $phone<br>Best time to contact: $contact <br>Injuries: $injuries</html>";
or
$message = "<br><br>Name: ".$name."<br>Phone: ".$phone."<br>Best time to contact: ".$contact ."<br>Injuries: ".$injuries."</html>";
moreover create a test.php
<?php
error_reporting(E_ALL);
$message = "<br><br>Name: ".$name."<br>Phone: ".$phone."<br>Best time to contact: ".$contact ."<br>Injuries: ".$injuries."</html>";
echo $message;
?>
This should return many errors called notice undefined variable, but that's OK and correct.
However if there is any error called error, then the providers have a problem...
I am not sure, that register globals can force an error: unexpected T_VARIABLE...
Shouldn't. If anything, a register globals issue will produce an undefined variable error.
maybe this one
"If you're under an Apache environment that has this option enabled, but you're on shared hosting so have no access to php.ini, you can unset this value for your own site by placing the following in an .htaccess file in the root:
php_flag register_globals 0
[/quote]"
If the file is not there do i just create it and add this line?
Thanks from the newbie
At previous hosting company it worked, on my servers it works, you tried and worked but at the current hosting company it is generating that error?
I told you to look at register globals because of your above quote. When you change your hosting and your php script stop working, always check register globals first. Most of the time that's the only issue.
You can create .htaccess file if it doesn't exist.