Forum Moderators: coopster
My employer is trying to get a contact page working with multiple department contacts
I have a few sites and work on them as a hobby so I was asked if I could help them out.
the form code is as follows
<form action="contact.php" method="POST" onSubmit="return formcheck(this);">
<table width="100%" cellpadding="2" cellspacing="2">
<tr>
<td width="30%"><div align="right">Department:</div></td>
<td width="70%">
<select name="department" size="1">
<option value="a" selected>Parts</option>
<option value="b">Sales</option>
<option value="c">Service</option>
<option value="d">Gen. Manager</option>
<option value="e">Receivables</option>
<option value="f">Payables</option>
</select> </td>
</tr>
<tr>
<td width="30%"><div align="right">Full Name:</div></td>
<td width="70%"><input name="name" type="text" size="40" maxlength="100">
</td>
</tr>
<tr>
<td width="30%"><div align="right">Email:</div></td>
<td width="70%"><input name="email" type="text" size="40" maxlength="100">
</td>
</tr>
<tr>
<td><div align="right">Telephone Number:</div></td>
<td><input name="telephone" type="text" size="40" maxlength="100"> </td>
</tr>
<tr>
<td><div align="right">How can we help?</div></td>
<td><textarea name="query" cols="30" rows="7"></textarea> </td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input name="submit" type=submit value=Submit>
</div></td>
</tr>
</table>
</form>
and this is the part of the contact.php that shows the error
<?php// Error Reporting
error_reporting(E_ALL);
// Receiving variables
@$name = addslashes($_POST['name']);
@$email = addslashes($_POST['email']);
@$telephone = addslashes($_POST['telephone']);
@$query = addslashes($_POST['query']);
$pfw_header = "From: $email";
$pfw_subject = "Customer Service Contact Form";
$pfw_email_to = (empty($_POST['department']))? 'default' : $_POST['department'];
$email_addresses = array('a' => 'parts@domain.com', 'b' => 'sales@domain.com', 'c' => 'service@domain.com', 'd' => 'taylorabqnm@domain.com', 'e' => 'ar@domain.com', 'f' => 'ap@domain.com', 'default' => 'taylorabqnm@domain.com');
if(!array_key_exists($pfw_email_to, $email_addresses)) {
$pfw_email_to = $email_addresses['default'];
}
else {
$pfw_email_to = $email_addresses[$pfw_email_to];
}
$pfw_message = "Client Name: $name\n"
. "\n"
. "Client Email: $email\n"
. "\n"
. "Client Number: $telephone\n"
. "\n"
. "Comments: $query\n"
if(!mail($pfw_email_to, $pfw_subject, $pfw_message, $pfw_header)) {
die('Error in sending mail.');
};
else {
header("Location: http://www.domain.com/TRE_EMAILSUBMITTED.html") or die('<strong>Thank you for contacting us for more information on our products and services.
We will have someone contact you shortly.</strong>');
}
?>
Please help.
Thanks for your time.
Roger S.
You have a semicolon where it is not needed:
if(!mail($pfw_email_to, $pfw_subject, $pfw_message, $pfw_header)) {
die('Error in sending mail.');
}; #<---- excess semicolon on this line
Take out the semicolon after the bracket like this:
if(!mail($pfw_email_to, $pfw_subject, $pfw_message, $pfw_header)) {
die('Error in sending mail.');
}
Some threads you may also be interested in reading:
The Basics of Submitting and Emailing Forms with PHP [webmasterworld.com]
Comabtting Webform Hijack [webmasterworld.com]
Good luck! :)
$pfw_message = "Client Name: $name\n"
. "\n"
. "Client Email: $email\n"
. "\n"
. "Client Number: $telephone\n"
. "\n"
. "Comments: $query\n"[b];[/b]# I added semicolon to end here