Forum Moderators: coopster

Message Too Old, No Replies

unverified T variable - new to PHP

         

scobby

3:40 pm on Mar 22, 2007 (gmt 0)

10+ Year Member



Hi all, i'm to new PHP and have been trying to resolve something. Previous hosting company had site working. When moved to a new company the php script stopped working. I'm getting the following message in the log:

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]

mcibor

4:08 pm on Mar 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The lines you show are correct.

Check the files on the server, there could be sth silly like a semicolon missing after 30 line. That's the most common problem for this type of error.
or you could have some letter or sign.

Regards
Michal

scobby

4:26 pm on Mar 22, 2007 (gmt 0)

10+ Year Member



Thanks. Is a ; required after each <br>

eelixduppy

4:32 pm on Mar 22, 2007 (gmt 0)



Try replacing the following:

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

scobby

4:36 pm on Mar 22, 2007 (gmt 0)

10+ Year Member



sorry i was looking at the print out but the actual php file in notepad has that as an entire line without breaking into line 32.

eelixduppy

7:07 pm on Mar 22, 2007 (gmt 0)



I'm not seeing anything wrong except for the fact that you are concatenating that string onto
$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! :)

scobby

7:25 pm on Mar 22, 2007 (gmt 0)

10+ Year Member



Thanks for the welcome!

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>";
}

eelixduppy

7:34 pm on Mar 22, 2007 (gmt 0)



I just ran most of this (everything but the mail function) on my server and I do not get any errors.

>> 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?

scobby

7:43 pm on Mar 22, 2007 (gmt 0)

10+ Year Member



That's what i don't understand. 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? The current hosting co says it's the script but works on others. Don't get it. based on your experience is that valid? or something going on with their servers? i imagine that are differences between yours, mine and previous host yet it worked.

mcibor

10:21 am on Mar 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't see any possible problems, even if they have some bad ini or other version of php.

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

scobby

7:43 pm on Mar 23, 2007 (gmt 0)

10+ Year Member



Tried the last test but didn't work. Could there be some php module that is not installed on their server? I created the test.php file and it did display in the browser. thanks again for the help.

Dinkar

6:25 am on Mar 24, 2007 (gmt 0)

10+ Year Member



scobby, here is the solution [in.php.net] to your problem :)

HTH.

mcibor

7:34 am on Mar 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Drinkar, I am not sure, that register globals can force an error: unexpected T_VARIABLE...
unless the error is sth else...

eelixduppy

11:37 am on Mar 26, 2007 (gmt 0)




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.

scobby

1:41 pm on Mar 26, 2007 (gmt 0)

10+ Year Member



Thanks. Going to take a look at the manual. is there any specific post that is tied to the problem i'm having?

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

Dinkar

6:06 pm on Mar 26, 2007 (gmt 0)

10+ Year Member



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.

joelgreen

6:50 pm on Mar 26, 2007 (gmt 0)

10+ Year Member



Maybe its some conflict with optimizer (if any installed on your hosting). Like Zend, etc.