Hello, I am trying to make a contact us form for a website. The form and accompanying php should work, i think. I am new to php but know how to program in general. The form and verify.php are below with some modifications for security.
contact.php snippet
<form method="post" action="verify.php" style="width: 384px">
<table style="width: 48%; height: 121px" class="style14">
<tr>
<td colspan="2" style="height: 41px">Contact us or write customer reviews using this form:</td>
</tr>
<tr>
<td style="width: 122px; height: 40px;">
<span class="style11">*</span>Department:</td>
<td style="height: 40px;">
<select name="sendto" style="width: 240px">
<option value="service@****.com">Service</option>
<option value="sales@****.com">Sales</option>
<option value="billing@****.com">Billing</option>
</select>
</td>
</tr>
<tr>
<td style="width: 122px; height: 40px;"><span class="style11">*</span>Name:</td>
<td style="height: 40px;">
<input name="Name" style="width: 240px" type="text" /></td>
</tr>
<tr>
<td style="width: 122px; height: 40px;">Company:</td>
<td style="height: 40px;">
<input name="Company" style="width: 240px" type="text" /></td>
</tr>
<tr>
<td style="width: 122px; height: 40px;">
<span class="style11">*</span>E-Mail:</td>
<td style="height: 40px;">
<input name="Email" style="width: 240px" type="text" /></td>
</tr>
<tr>
<td style="width: 122px; height: 40px;">Phone:</td>
<td style="height: 40px;">
<input name="Phone" style="width: 240px" type="text" /> </td>
</tr>
<tr>
<td style="width: 122px; height: 23px;">Message:</td>
</tr>
<tr>
<td colspan="2" style="height: 169px">
<textarea name="Message" style="width: 351px; height: 141px" class="style13"> </textarea></td>
</tr>
<tr>
<td colspan="2">
<tr>
<td colspan="2" class="style10">
<input name="send" type="submit" value="Submit" /></td>
</tr>
<tr>
<td colspan="2" class="style10">
<span class="style11">*</span> indicates
required field.</td>
</tr>
</table>
</form>
verify.php
$to = $_POST['sendto'];
$from = $_POST['Email'];
$name = $_POST['Name'];
$headers = "From: " . $from;
$subject = "Web Contact Form";
$message = $_POST['Message'];
$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Phone"} = "Phone";
$fields{"Message"} = "Message";
$body = "We Have received the following information:\n\n";
foreach($fields as $a => $b)
{
$body .= sprintf("%20s: %s\n",$b,$_POST[$a]);
}
$headers2 = "From: noreply@*****.com";
$subject2 = "Thank you for contacting us";
$autoreply = "some text";
$autoreply = wordwrap($autoreply, 65);
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{
header("Location: http://www.****.com/thankyou.html");
}
else
{
header("Location: http://www.****.com/error.html");
}
When I test this, it keeps coming back to error.html and the emails never get sent.
Please help. It is probably something very simple i'm just too close and am overlooking it. Also for reference, the site is hosted on and being tested on GoDaddy's servers. I don't know if that makes any difference.
Thanks!