...

View Full Version : Feedback form not 100%



Auriga
09-14-2005, 05:17 PM
First off here's the code...



<form name="contact" method="post" action="contact.php">
Your Name: <input type="text" name="Name"><br /><br />
Your Email: &nbsp;<input type="text" name="Email"><br /><br />
Subject: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="Subject"><br /><br />
Reason:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<select name="Reason">
<option value="1">General Feedback</option>
<option value="2">Advertising</option>
<option value="3">Site Suggestion</option>
<option value="4">Other Comment</option>
</select><br /><br />
Message:<br />
<textarea name="Message" cols="30" rows="8"></textarea><br />
<input type="submit" name="submit" value="Contact Us">
</form>

<?php

$emailSubject = $_POST['Subject'];
$emailMessage = $_POST['Message'];
$emailFrom = $_POST['Email'];
$emailFromName = $_POST['Name'];

$emailList[1] = 'myemailaddyhere';
$emailList[2] = 'myemailaddyhere';
$emailList[3] = 'myemailaddyhere';
$emailList[4] = 'myemailaddyhere :( ';

$emailTo = $emailList[$_POST['Reason']];

if (!empty($emailFrom)) {
$emailHeaders = 'From: "' . $emailName . '" <' . $emailFrom . '>';
} else {
$emailHeaders = 'From: "Auriga" <myemailaddyhere>';
}

if (!preg_match('/^([A-Z0-9\.\-_]+)@([A-Z0-9\.\-_]+)?([\.]{1})([A-Z]{2,6})$/i', $emailFrom) || empty($emailFrom)) {
echo 'The email address entered is invalid.';
} elseif (empty($emailSubject)) {
echo 'You must enter a valid subject.';
} elseif (empty($emailMessage)) {
echo 'You must enter a message to send to our team.';
} elseif (($_POST['Reason'] < 1) || ($_POST['Reason'] > 3)) {
echo 'You have selected an invalid department.';
} else {
// The sending code here
}
/* Send Email */
if (mail($emailTo, $emailSubject, $emailMessage, $emailHeaders)) {
echo 'You message has been sent!';
} else {
echo 'There was an internal error whilst sending your email.<br>';
echo 'Please try again later.';
}
?>


Which is from an article at php nerds (http://www.phpnerds.com/article/building-a-secure-contact-form/1).

My only problem is that when you first load the form up on the page (www.auriga.org.uk/contact.php) you'll notice that under the 'contact us' button it says...

The email address entered is invalid.
You must enter a valid subject.
etc
etc

Even before you fill out the form.

the only thing is i'm not sure what's wrong, i'm guessing something is in the wrong place...

NancyJ
09-14-2005, 05:57 PM
<form name="contact" method="post" action="contact.php">
Your Name: <input type="text" name="Name"><br /><br />
Your Email: &nbsp;<input type="text" name="Email"><br /><br />
Subject: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="Subject"><br /><br />
Reason:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<select name="Reason">
<option value="1">General Feedback</option>
<option value="2">Advertising</option>
<option value="3">Site Suggestion</option>
<option value="4">Other Comment</option>
</select><br /><br />
Message:<br />
<textarea name="Message" cols="30" rows="8"></textarea><br />
<input type="submit" name="submit" value="Contact Us">
</form>

<?php
if(isset($_POST['submit'])){

$emailSubject = $_POST['Subject'];
$emailMessage = $_POST['Message'];
$emailFrom = $_POST['Email'];
$emailFromName = $_POST['Name'];

$emailList[1] = 'myemailaddyhere';
$emailList[2] = 'myemailaddyhere';
$emailList[3] = 'myemailaddyhere';
$emailList[4] = 'myemailaddyhere :( ';

$emailTo = $emailList[$_POST['Reason']];

if (!empty($emailFrom)) {
$emailHeaders = 'From: "' . $emailName . '" <' . $emailFrom . '>';
} else {
$emailHeaders = 'From: "Auriga" <myemailaddyhere>';
}

if (!preg_match('/^([A-Z0-9\.\-_]+)@([A-Z0-9\.\-_]+)?([\.]{1})([A-Z]{2,6})$/i', $emailFrom) || empty($emailFrom)) {
echo 'The email address entered is invalid.';
} elseif (empty($emailSubject)) {
echo 'You must enter a valid subject.';
} elseif (empty($emailMessage)) {
echo 'You must enter a message to send to our team.';
} elseif (($_POST['Reason'] < 1) || ($_POST['Reason'] > 3)) {
echo 'You have selected an invalid department.';
} else {
// The sending code here
}
/* Send Email */
if (mail($emailTo, $emailSubject, $emailMessage, $emailHeaders)) {
echo 'You message has been sent!';
} else {
echo 'There was an internal error whilst sending your email.<br>';
echo 'Please try again later.';
}
}
?>

Auriga
09-14-2005, 06:05 PM
I've added in the bits you highlighted in red and get the following...

Parse error: parse error, unexpected $ in /home/auriga/public_html/contact.php on line 117

Auriga
09-14-2005, 06:06 PM
It's ok, forget that - i found it out...Thankyou!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum