Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING 1

Status
Not open for further replies.
Dec 1, 2009
7
AU
Hi there,

I am having trouble with my website. I'm a beginner with Dreamweaver so simplified answers are much appreciated. When you click 'send' on the contact form (which was created with a php file) it comes up with the following error:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/kerrikin/public_html/mail.php on line 32

My code for the php file - I have noted line 32 in BOLD (note, this isn't actually written in my code):

Code:
<body>

"<?php
//variables (change these)

$youremail = "test@hotmail.com";
// your email address

$subject = "Website Email";
// the subject of the email

$thankyou = "thankyou.html";
// thank you page

// don't change anything else

;if($email == ""){
?>
No email address added. Please go back.<br/>
"<?php
;}elseif($name == ""){
"?>
No name added. Please go back.<br/>
<?php
;}elseif($message == ""){
[b]"?>[/b]
No message added. Please go back.<br/>
"<?php
;}else{

$msg = ereg_replace("\\\'", "'", $message);
$msg = ereg_replace('\\\"', "\"", $msg);
$message1 = "from: $name\nemail: $email\nmessage:\n$msg1";

mail($youremail, $subject, $msg, "From: $email\r\nReply-to: $email\r\n");
?>
<meta http-equiv="refresh" content="0; url=<?echo $thankyou;?>"">
"<?php
}
"?>

</body>
</html>
 
Are the double quotes " before the PHP closing tag actually there?

If so, that is likely what's causing the error. They do nothing there.

You also have semi colons ";" next to "}" that end nothing.

This doesn't look like code DW would generate.

You are also setting the variable $youremail but the code then tries to check for the the variable $email which is never set.

Here, all corrected:
Code:
<?php
//variables (change these)

$youremail = "*********";
// your email address

$subject = "Website Email";
// the subject of the email

$thankyou = "thankyou.html";
// thank you page

// don't change anything else

if($email == ""){
?>
No email address added. Please go back.<br/>
"<?php
}elseif($name == ""){
?>
No name added. Please go back.<br/>
<?php
}elseif($message == ""){
?>
No message added. Please go back.<br/>
"<?php
}else{

$msg = ereg_replace("\\\'", "'", $message);
$msg = ereg_replace('\\\"', "\"", $msg);
$message1 = "from: $name\nemail: $email\nmessage:\n$msg1";

mail($youremail, $subject, $msg, "From: $email\r\nReply-to: $email\r\n");
?>
<meta http-equiv="refresh" content="0; url=<?echo $thankyou;?>"">
"<?php
}
?>

And you should have removed or obscured the email address. You don't want bots to be picking it up, and then spamming you.







----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thank you vacunita!

I have replaced my code with that and now the following message is coming up, even when I have filled out all sections of the form:

No email address added. Please go back.
"

If you can help me out that would be great.
 
I believe that vacunita only used **** instead of a valid email address just change that and you should be good to go.

Cheech

[Peace][Pipe]
 
As I said the script is checking for the $email variable but I don't see it set anywhere.

I did not add it because maybe it was in a part of the code you did not copy.

since it appears its not, add it to the first part:

Code:
//variables (change these)

$youremail = "*********";
// your email address
$email="********"
//address form which this email should be sent

...


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thank you so much for your replies!

But how do I know the email address of the person who is filling out the form. Isn't that what needs to go in the $email bit?

And wouldn't that mean that I'd also have to add in $name and $message variables?

Sorry, just a bit confused still.

I also added an additional 'Phone' section to the contact form just in the dreamweaver 'design section' - not in the code by just copying and pasting the 'Name' text&textbox. Has this stuffed things up?

You can see it on the website:


Thanks,

Jenna
 
There are 2 different variables here:

$youremail which you are setting manually, and $email which is the variable the error you posted is referring to.

The variable [red]$youremail[/red] is the one that is being used as the destination for the email in the line that actually sends the email:
Code:
mail([red]$youremail[/red], $subject, $msg, "From: [blue]$email[/blue]\r\nReply-to: [blue]$email[/blue]\r\n");

The [blue]$email[/blue] variable is the one that specifies the email address or person from which this email is being sent.

For example: When you send and email the "From" part of the email has your email address because the email is from YOU.

With that said, nowhere in the code you posted are you actually getting any values from a form.

Perhaps posting the form's code may help us understand whats going on.






----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thank you!

Here is my contact form code, I look forward to hearing from you:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Kerri Kingston Photography - Contact</title>
<style type="text/css">
<!--
body {
	background: #666666;
	margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
	padding: 0;
	text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
	color: #FFFFFF;
	background-color: #FFFFFF;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 100%;
}

/* Tips for Elastic layouts 
1. Since the elastic layouts overall sizing is based on the user's default fonts size, they are more unpredictable. Used correctly, they are also more accessible for those that need larger fonts size since the line length remains proportionate.
2. Sizing of divs in this layout are based on the 100% font size in the body element. If you decrease the text size overall by using a font-size: 80% on the body element or the #container, remember that the entire layout will downsize proportionately. You may want to increase the widths of the various divs to compensate for this.
3. If font sizing is changed in differing amounts on each div instead of on the overall design (ie: #sidebar1 is given a 70% font size and #mainContent is given an 85% font size), this will proportionately change each of the divs overall size. You may want to adjust based on your final font sizing.
*/
.oneColElsCtrHdr #container {
	width: 70em;  /* this width will create a container that will fit in an 800px browser window if text is left at browser default font sizes */
	background: #FFFFFF; /* the auto margins (in conjunction with a width) center the page */
	border: 1px none #000000;
	text-align: center; /* this overrides the text-align: center on the body element. */
	margin-top: 0;
	margin-right: auto;
	margin-bottom: 0;
	margin-left: auto;
	clear: none;
}
.oneColElsCtrHdr #header {
	padding: 0 10px 0 20px;  /* this padding matches the left alignment of the elements in the divs that appear beneath it. If an image is used in the #header instead of text, you may want to remove the padding. */
	background-color: #FFFFFF;
} 
.oneColElsCtrHdr #header h1 {
	margin: 0; /* zeroing the margin of the last element in the #header div will avoid margin collapse - an unexplainable space between divs. If the div has a border around it, this is not necessary as that also avoids the margin collapse */
	padding: 10px 0; /* using padding instead of margin will allow you to keep the element away from the edges of the div */
}
.oneColElsCtrHdr #mainContent {
	padding: 0 20px; /* remember that padding is the space inside the div box and margin is the space outside the div box */
	background: #FFFFFF;
}
.oneColElsCtrHdr #footer {
	padding: 0 10px;
	background-color: #FFFFFF;
} 
.oneColElsCtrHdr #footer p {
	margin: 0; /* zeroing the margins of the first element in the footer will avoid the possibility of margin collapse - a space between divs */
	padding: 10px 0; /* padding on this element will create space, just as the the margin would have, without the margin collapse issue */
}
a:link {
	text-decoration: none;
}
a:visited {
	text-decoration: none;
}
a:hover {
	text-decoration: none;
}
a:active {
	text-decoration: none;
}
.style20 {color: #333333}
.style28 {
	color: #333333;
	font-size: 12px;
}
.style29 {
	font-size: 11px;
	font-style: italic;
	font-family: Arial, Helvetica, sans-serif;
}
.style1 {color: #333333;
	font-size: x-small;
}
.style15 {	font-size: 13px;
	line-height: 22px;
}
.style32 {color: #333333; font-size: 12px; font-family: Arial, Helvetica, sans-serif; }
-->
</style>
</head>

<body class="oneColElsCtrHdr">

<div id="container">
  <div id="header">
    <h1 align="center"><img src="images/navigation/images/kerrikingston_navigation_FINAL_r2_c2.gif" alt="logo" width="213" height="146" border="0" /></h1>
    <p align="center"><a href="weddings_page_final.html"><img src="images/navigation/images/kerrikingston_navigation_FINAL_r3_c3.gif" alt="weddings" width="137" height="27" border="0" /></a><a href="babiesandbellies_page_final.html"><img src="images/navigation/images/kerrikingston_navigation_FINAL_r3_c4.gif" alt="b&b" width="211" height="27" border="0" /></a><a href="art_final.html"><img src="images/navigation/images/kerrikingston_navigation_FINAL_r3_c5.gif" alt="art" width="67" height="27" border="0" /></a><a href="info_final.html"><img src="images/navigation/images/kerrikingston_navigation_info_r2_c2.gif" alt="info" width="71" height="27" border="0" /></a><a href="contact_final.html"><img src="images/navigation/images/kerrikingston_navigation_FINAL_r3_c6.gif" alt="contact" width="105" height="27" border="0" /></a></p>
  <!-- end #header --></div>
  <div id="mainContent">
    <div id="mainContent2">
      <script src="[URL unfurl="true"]http://www.jotform.com/js/form.js?v2.0.1205"[/URL] type="text/javascript"></script>
      <table width="100%" align="center" cellpadding="25" cellspacing="0" class="tbmain">
<tr><td class="topleft" width="10" height="10"> </td>
<td rowspan="2" class="topmid">

  <form action="mail.php" method="post">
    <div align="left">
      <blockquote>
        <p align="left" class="style1 oneColElsCtrHdr"><span class="style15"><strong>Kerri Kingston Photography<br />
        </strong></span><span class="style15"><strong>P</strong> (03) 5358 3264<br />
                    </span><span class="style15"><strong>M </strong>0407 682 432<br />
                    <strong>E </strong>kerrik@tpg.com.au</span></p>
        <p align="left" class="style1 oneColElsCtrHdr">
        <form action="mail.php" method="post">
        <span class="style32">Name 
                    <input type="text" name="name">
        </span>
        <p class="style32">          Email 
            <input type="text" name="email">
            <br/>
            </p>
        <p><span class="style32">Message</span><span class="style32"></span><span class="style28"><br />
          <span class="style29">(Incl. Type of Photography, Date and Location etc.)</span></span><br/>
                <textarea name="message" cols="40" rows="5"></textarea>
                <br/>
                <input type="submit" value="send">
            </p>
        <p align="left" class="oneColElsCtrHdr style1">All images on this website are Copyright of <br />
          Kerri Kingston Photography. </p>
        <p class="style28"></p>
        <p><br/>
        </p>
      </blockquote>
    </div>
    </form></td>
<td class="topright" width="10" height="10"> </td>
  </tr>
<tr>
<td class="midleft" width="10"> </td>
<tr >
  <td width="150" class="left style20" > </td>
 </tr>
</table>
</div>
</div>
</form>
</td>
<td class="midright" width="10">   </td>
</tr>
<tr>
 <td class="bottomleft" width="10" height="10"> </td>
 <td class="bottommid"> </td>
 <td class="bottomright" width="10" height="10"> </td>
</tr>
</table>
<script type="text/javascript">
validate("q_form_93242103688");
</script>

</div></td
  ></tr>
  <tr >
    <td width="150" height="184" class="left" ><div align="left"></div></td>
    <td class="right"><div align="left">
      <p align="left">  </p>
    </div></td>
  </tr>
</table>
<h1 align="center">
        <!-- end #footer -->
</h1>
  </div>
</div>
  <!-- end #container --></div>
</body>
</html>
 
Well you have 2 forms pointing to the same place (email.php) one inside the other. That's just not right.


Code:
[red] <form action="mail.php" method="post">[/red]
[gray]    <div align="left">
      <blockquote>
        <p align="left" class="style1 oneColElsCtrHdr"><span class="style15"><strong>Kerri Kingston Photography<br />
        </strong></span><span class="style15"><strong>P</strong> (03) 5358 3264<br />
                    </span><span class="style15"><strong>M </strong>0407 682 432<br />
                    <strong>E </strong>kerrik@tpg.com.au</span></p>
        <p align="left" class="style1 oneColElsCtrHdr">
       [/gray][blue] <form action="mail.php" method="post">[/blue][gray]
        <span class="style32">Name
                    <input type="text" name="name">
        </span>
        <p class="style32">          Email
            <input type="text" name="email">
            <br/>
            </p>
        <p><span class="style32">Message</span><span class="style32"></span><span class="style28"><br />
          <span class="style29">(Incl. Type of Photography, Date and Location etc.)</span></span><br/>
                <textarea name="message" cols="40" rows="5"></textarea>
                <br/>
                <input type="submit" value="send">
            </p>
        <p align="left" class="oneColElsCtrHdr style1">All images on this website are Copyright of <br />
          Kerri Kingston Photography. </p>
        <p class="style28"></p>
        <p><br/>
        </p>
      </blockquote>
    </div>
[/gray][blue]</form>[/blue][gray]</td>
<td class="topright" width="10" height="10"> </td>
  </tr>
<tr>
<td class="midleft" width="10"> </td>
<tr >
  <td width="150" class="left style20" > </td>
 </tr>
</table>
</div>
</div>
[/gray][red]</form>[/red]


Remove on of the form tags ( <form ...> ) and a corresponding closing tag ( </form> ).

Once your form submits to email.php you need to acquire the values from it to make your script work and send the email.
So Basically you'll want to do this:

Code:
<?php
if(isset($_POST['send'])){
//variables (change these)

$destination_email = "*********";
// your email address

$subject = "Website Email";
// the subject of the email

$thankyou = "thankyou.html";
// thank you page

// don't change anything else

//Get Values from form:

if(isset($_POST['email'])&&!empty($_POST['email'])){
$email=$_POST['email'];
}
else{
exit("Email not set, please go back and try again");
}

if(isset($_POST['name'])&&!empty($_POST['name'])){
$name=$_POST['name'];
}
else{
exit("Name not set, please go back and try again");
}

if(isset($_POST['message'])&&!empty($_POST['message'])){
$message=$_POST['message'];
}
else{
exit("Message not set, please go back and try again");
}

if(isset($_POST['phone'])&&!empty($_POST['phone'])){
//Add Phone number to message
$message.="\n Phonenumber: " . $_POST['phone'];

}
else{
exit("Phone not set, please go back and try again");
}


$msg = ereg_replace("\\\'", "'", $message);
$msg = ereg_replace('\\\"', "\"", $msg);

mail($youremail, $subject, $msg, "From: $email\r\nReply-to: $email\r\n");
?>
<meta http-equiv="refresh" content="0; url=<?echo $thankyou;?>"">
"<?php
}
?>

I tested the code and it should work. Assuming the server where this page is being hosted is capable of sending emails.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Great! Thank you!
Now it goes to to mail.php file - which I have put a (Thank you. Your message has been sent!) message. However, no emails have come up in the email inbox that I have set up with the form. Could this be a problem with my host?

Also, if I wanted to add a 'Phone' section on the form, which part of the code on the contact.html would I copy?

Thanks again,

Jenna
 
Code:
[gray]
<span class="style32">Name
                    <input type="text" name="name">
        </span>
[red]
<span class="style32">Phone
                    <input type="text" name="phone">
        </span>

[/red]
        <p class="style32">          Email
            <input type="text" name="email">
            <br/>
            </p>
        <p>
[/gray]

As far as the emails go, the mail function doesn't return any errors. Only true or false. True if the email was accepted by the server for delivery, and false if it wasn't.



You could add the following to make sure the mail function is passing the email on to the server:

Code:
if(mail($youremail, $subject, $msg, "From: $email\r\nReply-to: $email\r\n")){
echo "email was successfully passed for delivery to server";
}
else{
echo "Email could not be passed for delivery";
}

If that returns the "email was successfully passed..." part and there is no email received still then its server problem.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thank you.

There doesn't seem to be any errors coming through.
I still havent had any emails come through so I have contacted the host.

However, if I dont enter a 'name' or 'message' etc into the contact form - no errors come up either, eg. No Name set, please go back. As instructed in the mail.php

Also, once I have added the 'phone' section into the contact form, do I have to add more code into the mail.php to say 'no phone set, please go back'

Sorry this is taking so much of your time.

 
The code I posted already took into account the Phone section:

Code:
if(isset($_POST['phone'])&&!empty($_POST['phone'])){
//Add Phone number to message
$message.="\n Phonenumber: " . $_POST['phone'];
}

else{
exit("Phone not set, please go back and try again");
}

I suggest you read the code a little closer.

As far as
However, if I don't enter a 'name' or 'message' etc into the contact form - no errors come up either, eg. No Name set, please go back. As instructed in the mail.php
I find that very odd. I just tried it, and the code I posted before works for me. It does however only return one error at a time. That is if you leave more than one of the
inputs empty it will only return an error for the first one it finds is not filled in.

The code can be altered to report all of them, but I think it be better to understand it as it is now before adding more complexity.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top