Author Topic: Contact Form Help [Beginner]  (Read 92 times)

GiANTOnFire

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Contact Form Help [Beginner]
« on: January 27, 2012, 11:45:37 AM »
So I'm using PHP for the first time, and have written this reasonably simple contact form, but it won't work and I can't for the life of me work out why. I get this error:

Parse error: syntax error, unexpected T_STRING in \\nas39ent\Domains\b\black-kite.co.uk\user\htdocs\html_form_send.php on line 5


and don't know how to fix it. Here is the code:


PHP Code: [Select]
<?php
if(isset($_POST['email'])) {


$email_to "dkg@black-kite.co.uk";
$email_subject "Web Form Message";

function 
died($error) {

echo 
"We are very sorry, but there were error(s) found with the form you submitted. ";
echo 
"These errors appear below.<br /><br />";
echo 
$error."<br /><br />";
echo 
"Please go back and fix these errors.<br /><br />";
die();
}

// validation expected data exists
if(!isset($_POST['name']) ||
!isset(
$_POST['company']) ||
!isset(
$_POST['email']) ||
!isset(
$_POST['telephone']) ||
!isset(
$_POST['message'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}

$name $_POST['name']; // required
$email_from $_POST['email']; // required
$telephone $_POST['telephone']; // not required
 
$company $_POST['company']; // not required

$message $_POST['message']; // required

$error_message "";
$email_exp '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!
preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';

$string_exp "/^[A-Za-z .'-]+$/";
if(!
preg_match($string_exp,$name)) {
$error_message .= 'The name you entered does not appear to be valid.<br />';


if(
strlen($message) < 2) {
$error_message .= 'The message you entered does not appear to be valid.<br />';

if(
strlen($error_message) > 0) {
died($error_message);

$email_message "Form details below.\n\n";

function 
clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return 
str_replace($bad,"",$string);

$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
  
$email_message .= "Company: ".clean_string($company)."\n";
$email_message .= "Message: ".clean_string($message)."\n";


// create email headers
$headers 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' phpversion();
@
mail($email_to$email_subject$email_message$headers);¬† 
?>

Thank you for your message. We will be in touch.

<?php
}
die();
?>



Any help would be greatly appreciated - and preferably in laymans terms. I am new to PHP..

jSherz

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 403
  • Karma: +4/-0
    • View Profile
    • jSherz.com
Re: Contact Form Help [Beginner]
« Reply #1 on: January 27, 2012, 12:26:19 PM »
PHP Code: [Select]
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';

$string_exp "/^[A-Za-z .'-]+$/";
if(!
preg_match($string_exp,$name)) {
$error_message .= 'The name you entered does not appear to be valid.<br />';


if(
strlen($message) < 2) {
$error_message .= 'The message you entered does not appear to be valid.<br />';

if(
strlen($error_message) > 0) {
died($error_message);


I can't see anything wrong with line 5 itself, but you have a series of IF's with starting { brackets and no ending ones.
Looking for PHP tutorials? View mine. Please use code or PHP tags in your posts.

GiANTOnFire

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Contact Form Help [Beginner]
« Reply #2 on: January 27, 2012, 01:18:50 PM »
Ooh, thanks for pointing that out, I have now closed the brackets.

It still doesn't work. Could the fact that when I open it to edit straight from the server it has these ¬†¬†¬†¬†¬†¬ at the beginning of every line be making a difference?

I doubt it, but I'm clutching at straws here!