DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   please help (http://www.daniweb.com/forums/thread160284.html)

addsf1 Dec 1st, 2008 1:27 pm
please help
 
I keep getting this message what is wrong with my sacript???

Parse error: syntax error, unexpected $end in /home/sites/thefieldinggallery.co.uk/web/contact_form.php on line 65

here is the php script:

<?php
/* subject and email Variables */
 $emailSubject = 'Crazy PHP Scripting';
 $webMaster = 'info@thefieldinggallery.co.uk';
 
/* Gathering Data Variables */
 $nameField = $_POST['name'];
 $surnameField = $_POST['surname'];
 $emailField = $_POST['email'];
 $telephoneField = $_POST['telephone'];
 $commentsField = $_POST['comments'];
 
  $body = <<<em
<br><hr><br>
name: $name <br>
surname: $surname <br>
email: $email <br>
telephone: $telephone <br>
comments: $comments <br>
EOD;
 $headers = "From: $email\r\n";
 $headers ,= "Content-type: text/html\r\n";
 $success = mail($webMaster, $emailSubject, $body, $headers);
 
/*Results rendered as HTML */
 $theResults = <<<EOD
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table width="50%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="2"><img src="images/strap.jpg" alt="header" width="769" height="216" /></td>
  </tr>
  <tr>
    <td width="11%"><div align="center"><a href="index.html">Back to Home</a></div></td>
    <td width="89%"><div align="center">
      <p>&nbsp;</p>
      <p><font color="#FF0000" size="+7"><u>Thank you</u> <font color="#000000">for your  we have recived you Questions / Comments and we will reply to you</font> <u>as soon as possible</u></font></p>
    </div></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><div align="right">Copyright &copy; <a href="http://www.thefieldinggallery.co.uk">www.thefieldinggallery.co.uk</a></div></td>
  </tr>
</table>
</body>
</html>
EOD;
echo "$theresults";
?>

buddylee17 Dec 1st, 2008 2:16 pm
Re: please help
 
When using heredoc, you must open and close the variable with the same identifier.
$body = <<<em
<br><hr><br>
name: $name <br>
surname: $surname <br>
email: $email <br>
telephone: $telephone <br>
comments: $comments <br>
EOD;
should be:
$body = <<<EOD
<br><hr><br>
name: $name <br>
surname: $surname <br>
email: $email <br>
telephone: $telephone <br>
comments: $comments <br>
EOD;

Also, variables in php are case sensitive, so you'll have a blank page unless you change
echo "$theresults";
to
echo "$theResults";

addsf1 Dec 1st, 2008 2:59 pm
Re: please help
 
Thank you you are a life saver Cheers bro

buddylee17 Dec 1st, 2008 3:11 pm
Re: please help
 
Glad to help.

buddylee17 Dec 1st, 2008 3:15 pm
Re: please help
 
Next time, wrap your code in code tags when posting to keep things neat. There are plenty of people here to help out. Keeping things neat will improve your chances of getting help.

addsf1 Dec 1st, 2008 3:23 pm
Re: please help
 
Im new at this and got it from a tutorial. i don't know how to wrap in a tag sorry its messy!
I do have another question though as it has worked and the mail is coming through but the content of the form isn't attached just the headers. can you see what is wrong there???? i would be most grateful

buddylee17 Dec 1st, 2008 3:44 pm
Re: please help
 
Wrap the code like so:
[code=php]Code goes here[/code]

As to your problem, your email contains undefined variables. For instance you define namefield as
$nameField = $_POST['name'];
but in the email you send, you have the undefined variable $name instead of the defined $nameField.

addsf1 Dec 1st, 2008 4:01 pm
Re: please help
 
OK so do i take that as it should look like this?

$nameField = $_POST['nameField'];

I hope im not doing your head in with the questions but as i said i am a total newby at this

buddylee17 Dec 1st, 2008 4:39 pm
Re: please help
 
The name the element has in the form goes inside the brackets.
So if your form has
<input name="name" type="text" id="name" tabindex="16" />
After the form is submitted, PHP can assign the value posted to the variable. Here we assign the value of the textbox above to the variable $nameField:
$nameField=$_POST['name'];
Now if you want to use that variable in your email, you'll need to use the variable just defined.
$body = <<<EOD
<br><hr><br>
name: $nameField <br>

Get it??

addsf1 Dec 1st, 2008 5:05 pm
Re: please help
 
My Friend as far as i am concerned you are a god in the PHP world
i can not say thank you enough

Cheers

Adam


All times are GMT -4. The time now is 2:08 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC