Use this, works like a dream:
HTML Code:
<?php
if(isset($_POST['button_x'])) { // use button_x ONLY if using an image - if not use just $_POST['button'];
if(empty($_POST['message'])) {
header("location:?e=1");
exit;
}
if(empty($_POST['email'])) {
header("location:?e=1");
exit;
}
if(empty($_POST['tel'])) {
header("location:?e=1");
exit;
}
if(empty($_POST['name'])) {
header("location:?e=1");
exit;
}
if(!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $_POST['email'])) {
header("location:?e=2");
exit;
}
$subject = "Website Message - Winner Avant";
$name = $_POST['name'];
$telephone = $_POST['tel'];
$theiremail = $_POST['email'];
$message = $_POST['message'];
$ip = $_SERVER['REMOTE_ADDR'];
$msg = '
<html>
<body style="font-family:Verdana, Arial, Helvetica, sans-serif;">
<p>A message has been sent from the Winner Avant website. The message was from ' . $name . '.</p>
<p>Email: <strong>' . $theiremail . '</strong></p>
<p>Telephone: <strong>' . $telephone . '</strong></p>
<div style="width:700px; height:auto;">
<p>The message is:<br /><pre style="font-weight:bold; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word; font-family:Verdana, Arial, Helvetica, sans-serif;">' . stripslashes($message) . '</pre></p>
</div>
<p>The message was sent on ' . date('j F Y H:i:s') . '</p>
<p>Their IP address is ' . $ip . '</p>
</body>
</html>
';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Winner Avant <donotreply@yourwebsite.co.uk>' . "\r\n";
$headers .= 'Reply-To: ' . $name . ' <' . $theiremail . '>' . "\r\n";
$email = 'sales@winnerhandling.co.uk';
if (@mail($email, $subject, $msg, $headers)) {
header("location:?e=3");
exit;
}
header("location:?e=0");
exit;
} ?>
And for the errors, use this:
HTML Code:
<?php
if(isset($_GET['e'])):
switch($_GET['e']):
case 0:
echo "<p>An error occoured, please contact the server administrator.</p>";
break;
case 1:
echo "<p>Please fill in all the fields.</p>";
break;
case 2:
echo "<p>Please enter a valid email address.</p>";
break;
case 3:
echo "<p>Your message was sent. We will reply shortly.</p><p>To send another message, <a href=\"support.php\">click here</a>.";
break;
endswitch;
else:
?>
<form action="" method="post">
<p>Please fill in the following details below. We aim to get back to you within 24 hours.</p>
<p><input type="text" name="name" id="name" /></p>
<p><input type="text" name="tel" id="tel" /></p>
<p><input type="text" name="email" id="email" /></p>
<p><textarea name="message" id="message" cols="1" rows="1"></textarea></p>
<?php // ADD CAPCHA ?>
<p><input type="image" class="button" name="button" src="images/send.png" /></p>
</form>
<?php endif;?>
Bookmarks