Hi,
I am trying to get my form to send an order to an email. This works ok but when I put the headers in for the from label, it goes into my junk mail.
Is there any way to get this to go into my inbox successfully? Someone saud to me the from headers have to be exactly right.
Can anyone shed some light please on how I can fix this?
<form method="post" action="mailer.php">
<div id="form_left">
Your Name:<br />
<input type="text" name="name" size="24" /><br />
<br />
Your Email:<br />
<input type="text" name="email" size="24" />
</div>
<div id="form_right">
Your Date of Birth:<br />
<input type="text" name="dob" size="24" /><br />
<br />
Number:<br />
<input type="text" name="nin" size="24" /><br />
<br />
</div>
<br />
<div id="form_left2">
Dr:<br />
<select name="contact_type">
<option>Mark</option>
<option>Colin</option>
<option>1</option>
<option>2</option>
</select>
</div>
<div id="form_right2">
Pickup Point:<br />
<select name="pickup">
<option>Local Practice</option>
<option>Option</option>
<option>Another Option</option>
<option>Another Option 2</option>
</select>
</div>
<br /><br /><br />
Please specify the details of your order, including name & quantity :<br />
<textarea rows="10" name="message" cols="55"></textarea>
<br />
<p>Please ensure that you have filled out all important information before submitting.</p>
<p><b>You must provide photographic ID when picking up your order.</b></p>
<input type="submit" value="Submit" name="submit" />
</form>
And my PHP:
<?php
if (isset($_POST['submit'])) {
switch($_POST['contact_type']) {
case 'mark':
$to = 'email@email.com';
$dr = 'Mark';
break;
case 'Colin';
$to = 'email@email.com';
$dr = 'Colin';
break;
case '1':
$to = 'email@email.com';
$dr = '1';
break;
case '2':
$to = 'email@email.com';
$dr = '2';
break;
}
{
switch($_POST['pickup']) {
case 'Local Practice':
$to = 'email@email.com';
$pickup = 'Local Practice';
break;
case 'Boots';
$to = 'email@email.com';
$pickup = 'Boots';
break;
case 'Another Option':
$to = 'email@email.com';
$pickup = 'Another Option';
break;
case 'Another Option 2':
$to = 'email@email.com';
$pickup = 'Another Option 2';
break;
}
$subject = "Website Order";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$dob_field = $_POST['dob'];
$nin = $_POST['nin'];
$headers = "MIME-Version: 1.0\
";
$headers .= "Content-type: text/plain; charset=iso-8859-1\
";
$headers .= "From: User from site <user@thesite.com>\
";
$headers .= "X-Mailer: PHP's mail() Function\
";
$message = $_POST['message'];
if (strlen(trim($message)) > 0) {
$body = "From: $name_field\
\
E-Mail: $email_field\
\
Date of birth: $dob_field\
\
National Insurance Number: $nin\
\
Dr: $dr\
\
Pickup: $pickup\
\
Message: $message\
";
if (mail($to, $subject, $body, $headers)) {
echo "<h3>Thanks! Your email has been sent <br />We will process your order as soon as possible.</h3>";
} else {
echo 'Cannot sent mail';
}
} else {
echo "<h3>Error! <br />Please ensure that all fields are filled out in order to email us!</h3>";
}
}
}
?>