Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-05-2012, 06:58 AM   PM User | #1
lesh
New Coder

 
Join Date: Nov 2011
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
lesh is an unknown quantity at this point
Help with contact form

Hi all, when posting my contact form I get this error:
Quote:
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
lesh is offline   Reply With Quote
Old 08-05-2012, 01:59 PM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 08-05-2012, 08:55 PM   PM User | #3
lesh
New Coder

 
Join Date: Nov 2011
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
lesh is an unknown quantity at this point
Here is my contact form php

PHP Code:
<?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\">";
}
?>
lesh is offline   Reply With Quote
Old 08-05-2012, 09:11 PM   PM User | #4
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
PHP Code:
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

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:

PHP Code:
$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.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS

Last edited by AndrewGSW; 08-05-2012 at 09:17 PM.. Reason: Added apostrophes to expression
AndrewGSW is offline   Reply With Quote
Old 08-05-2012, 09:33 PM   PM User | #5
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,511
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by lesh View Post
PHP Code:
  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.

Quote:
Originally Posted by lesh View Post
PHP 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"
Quote:
Originally Posted by AndrewGSW View Post
BTW All that '$Body .=' is inefficient/a little messy - it could be constructed in fewer lines:

PHP Code:
$Body "Name: $Name\n"// etc.
$Body .= "Tel: $Tel\n"
Thats still messy. The heredoc would be far better for this:
PHP Code:
$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.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:27 PM.


Advertisement
Log in to turn off these ads.