...

View Full Version : Help with contact form



lesh
08-05-2012, 07:58 AM
Hi all, when posting my contact form I get this error:

Parse error: syntax error, unexpected T_STRING in /home/friddbui/public_html/Assets/contactengine.php on line 38
I'm not sure what the problem is. Perhaps I've incorrectly written where I'm wanting to direct then once they've submitted the contact form.
Could somebody please help. Here's a link to my contact page
http://www.friddbuilding.co.nz/contact.html

AndrewGSW
08-05-2012, 02:59 PM
That html link doesn't help as the error is in your PHP.

unexpected T_STRING usually (for me) indicates a misplaced comma or bracket.

lesh
08-05-2012, 09:55 PM
Here is my contact form php


<?php

$EmailFrom = "chriscoyier@gmail.com";
$EmailTo = "a.harper@xtra.co.nz";
$Subject = "Website enquiry";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));

// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content="http://www.friddbuilding.co.nz/contactsuccess.html">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

AndrewGSW
08-05-2012, 10:11 PM
print "<meta http-equiv=\"refresh\" content=\"0;URL='http://www.friddbuilding.co.nz/contactsuccess.html'\">";

You could have corrected this by comparing it to your other examples :rolleyes:

meta, refresh is a legacy method and use of header() to re-direct is preferred.

BTW All that '$Body .=' is inefficient/a little messy - it could be constructed in fewer lines:


$Body = "Name: $Name\n"; // etc.
$Body .= "Tel: $Tel\n";

or one or two bigger lines.

Added: And you should remove, or use fake, email addresses in your posted-code.

tangoforce
08-05-2012, 10:33 PM
print "<meta http-equiv=\"refresh\" content="http://



That last " before http:// should be escaped. The http:// is the unexpected T_STRING while everything after the // is a comment. If you look at your code in an editor like notepad++ you will see this because the colours change around those parts of that line of code.





$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";





BTW All that '$Body .=' is inefficient/a little messy - it could be constructed in fewer lines:



$Body = "Name: $Name\n"; // etc.
$Body .= "Tel: $Tel\n";



Thats still messy. The heredoc would be far better for this:


$Body = <<< STOP

Name: $Name
Tel: $Tel
Etc: $Etc

STOP;


$Body will then hold a variable that looks exactly like the text there with the variables replaced with their values and the lines / carriage returns preserved.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum