No luck with contact forms, help me

Anyone have any good tips for up to date complete contact forms with validation and everything that is easy to implement?

ATM my form looks like this, no validation.


<form id="contact-form" action="email.php" method="post">
	<div class="input-wrapper1">
		<label for="name">namn</label><input type="text" name="name" id="name" />
	</div>
	<div class="input-wrapper2">
		<label for="mail">epost</label><input  type="text" name="mail" id="mail" />
	</div>
	<label for="msg">ärende</label><textarea name="msg" id="msg"></textarea>
	<button type="submit" name="send" id="send"><i <i class="icon-angle-circled-right"></i></button>
</form>
<?php 

$name = $_POST['name'];
$mail = $_POST['mail'];
$msg = $_POST['msg'];
$formcontent="From: $name \
 Mail: $mail \
 Message: $msg";
$recipient = "mail@outlook.com";
$subject = "Contactform submit from RB";
$mailheader = "From: $mail \\r\
";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";

?>

Here is how I do it with server and client side validation. http://www.websitecodetutorials.com/code/php/how-to-html-form-with-php-js-captcha-validation.php. Works perfect.

thx alot. will give it a try.

There is a lot to remember when adding validation to inputs to your website. If your wanting to use a fully implemented validation procedure I would suggest using a framework like Codeignighter. I’d also stick some form of Captcha field into your form, helps stop spammers firing off a million and one emails from your server. Good luck!

It should probably be mentioned that the above code doesn’t apply any kind of validation to what is passed to the mail function.
This means that you could potentially insert additional headers and use the contact form as a spam tool.

You can read more here: http://www.securephpwiki.com/index.php/Email_Injection

Mine accounts for headers and etc. I pieced it together a long while back. Quite happy with it. Form processing is probably the hardest thing I’ve ever done to get right. Usually if you grab some one piece of code it has like 10 pages of mumbo jumbo. I was never ok with that. I needed to know what it was doing.