PDA

View Full Version : Php mail form error


urbanrays
01-22-2009, 06:52 PM
Hi could somebody have a look at this error code and php script and tell me what is up with it

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in E:\domains\u\urbanrays.co.uk\user\htdocs\mail.php on line 24

"<?php

$youremail = "contact@urbanrays.co.uk";

$subject = "Contact from Website";

$thankyou = "index.htm";

;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 "THIS IS LINE 24"
;}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
}
"?>

Here is my html code
<form name="contact" method="post" action="mail.php">
<div id="contact_form">
<label class="contact_form">Name:</label>
<input name="name" type="text" class="contact_input" id="name" />
<div class="cleardiv"></div>
<label class="contact_form">Email:</label>
<input name="email" type="text" class="contact_input" id="email" />
<div class="cleardiv"></div>
<label class="contact_form">Message:</label>
<textarea name="message" cols="" rows="" class="contact_textarea" id="message"></textarea>
<div class="cleardiv"></div>
<input type="submit" name="Submit" value="Submit" class="contact_submit"/>
</form>

Thanks for any help

davidj
01-22-2009, 08:00 PM
I have cleaned the code up as there were visible errors

i have not tested the code though so it still may not work but at least its tidy and easier to debug


<?php

$youremail = "contact@urbanrays.co.uk";
$subject = "Contact from Website";
$thankyou = "index.htm";

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



fancy learning how to code by me?

urbanrays
01-22-2009, 08:45 PM
Hi

Thanks for cleaning the code but now it is saying that I have not entered a email address when I have fault on line 7 if($email == ""){ ?>


Cheers

edbr
01-22-2009, 11:32 PM
recheck your code as this looks right

edbr
01-22-2009, 11:35 PM
and check that $email is properly defined ie $_POST['email']=$email:

it could be your form field name is wrong

urbanrays
01-22-2009, 11:56 PM
Thanks for your help chaps sorted it
stupid spelling mistake