Hello everyone
I am having this simple contact form and i want to make the name , email fields to be required.Also i want to add a thank you message after someone press the sumbit button.
Your help will be much appreciated.
Php
<?
if ($_POST['name'] == '' || $_POST['subj'] == '' || $_POST['mail'] == '' || $_POST['message'] == '')
exit;
#YOUR E-MAIL
define('TO', 'email@yourdomain.com');
##E-MAIL SUBJECT
define('SUBJECT', 'Contact Form!');
function sendEmail($to, $from, $subj, $body)
{
$date = date( 'r' );
$phpversion = phpversion();
$boundary = md5( time() );
$headers = <<<END
From: $from
Date: $date
MIME-Version: 1.0
Content-Type: multipart/related; boundary="$boundary"
END;
$body = <<<END
--$boundary
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: 7bit
$body
END;
mail(trim($to), trim($subj), $body, $headers );
}
sendEmail(TO, trim($_POST['mail']), SUBJECT, 'E-Mail from: '.trim($_POST['name']).'<br /><br/>Subject: '.nl2br(trim($_POST['subj'])).'<br /><br/>Message: '.nl2br(trim($_POST['message'])));
header('Location: contact.html');
?>
html
<form action="mail.php" method="post">
<input class="inp" name="name" type="text" value="Name:" onfocus="if (this.value == 'Your Name') this.value = '';" onblur="if (this.value == '') this.value = 'Your Name';" />
<input class="inp" name="mail" type="text" value="Email:" onfocus="if (this.value == 'Email') this.value = '';" onblur="if (this.value == '') this.value = 'Email';" />
<input class="inp" name="subj" type="text" value="Subject:" onfocus="if (this.value == 'Subject') this.value = '';" onblur="if (this.value == '') this.value = 'Subject';" />
<textarea class="mess" name="message" cols="" rows="" onfocus="if (this.value == 'Message') this.value = '';" onblur="if (this.value == '') this.value = 'Message';" >Message: