please don't take the follwoing bad but your code is ugly doesn't check anything and is highly likely to get spammed!.
try this code uses recaptcha to prevent spam, uses email validation to match emails and also checks and see if no fleids left blank.
also uses no database takes the message and checks it then sends email to given email address.
these are just some of the features i use to prevent forms from getting spammed or using the form to spam!.
<?php
$name=$_POST['name']; //first form field name
$email1=$_POST['email1']; //second form field email 1
$email2=$_POST['email2']; //3rd form field email 2
$topic=$_POST['topic']; //4th form field email subject
$detail=$_POST['detail']; // 5th field the message
/* checking to see if the form fields are empty or filled if 1 is empty die and show error*/
if(empty($name) || empty($email1) || empty($email2) || empty($topic) || empty($detail)) {
die(" you are missing information please fillout all feilds and submit again! ");
}
/* seeing if email 1 matches email 2 or die and show error */
if ( $email1 !== $email2 ) {
die (" your emails do not match");
}
/* reCaptcha code must download from recaptcha */
require_once('recaptchalib.php');
$privatekey = "6Le0OQwAAAAAAKzvfLXUoKxSMm6-j80_Bn_KWAZX ";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
}
// send mail variables after if checking passed
$to="you@yourmail.com"; //your email
$subject="new message: $topic"; //your subject with the topic variable
$message="$name says: $detail"; // the message to send
$headers="From: $email1"; // extra header email
$send= mail($to , $subject , $message , $headers); // function to send email
if (!$send) {
die( "mailer failed please try again"); // die if failed
}
header("Location: success.php"); // success page
?>
and gives you an example of what to protect and this can be expanded on as far as security there is never to much checking!.