DGinformatisering

DG Contactform

A ready-to-go contactform. Just copy-paste to a snippet and make your call from the page. Don't forget to fill in the e-mail address...

<?php
/**********************************************************
************ (c) 2012 DG Informatisering    *************
***********************************************************/
$errors = Array();
if(isset($_POST["contact_name"])){
 if(strlen(@$_POST["contact_name"])<2) $errors["naam"]='<b>Invalid name</b><br/>';
 if(!@eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]{2,}\.([a-zA-Z0-9]{2,})$', @$_POST["contact_email"] )) $errors["email"]='<b>Invalid e-mail address</b><br/>';
 if(trim(@$_POST["contact_message"])=="") $errors["message"]='<b>No message entered</b><br/>';
}
if(sizeof($errors)==0 && isset($_POST["contact_name"])){
    $headers = 'From: '. @$_POST["contact_email"] . '\r\n' .
        'Reply-To: '. @$_POST["contact_email"]. '\r\n' .
        'X-Mailer: PHP/' . phpversion();
    mail('info@yoursite.nl', 'Contactform', @$_POST["contact_message"], $headers);
    $form = '<br/>Message sent';
}else {

$form = '
<form id="contactForm" class="contactform" method="post">
<div>
<label for="contact_name">Name*:</label><br />'.@$errors["naam"].'
<input id="contact_name" name="contact_name" size="30" class="required" minlength="2" value="'.@$_POST["contact_name"].'" />
</div>
<div>
<label for="contact_email">E-Mail address*:</label><br />'.@$errors["email"].'
<input id="contact_email" name="contact_email" size="30"  class="required email" value="'.@$_POST["contact_email"].'" />
</div>
<div>
<label for="contact_phone">Phone number:</label><br />
<input id="contact_phone_NA_format" name="contact_phone_NA_format" size="14" class="phone" value="'.@$_POST["contact_phone_NA_format"].'" maxlength="14" />
</div>
<div>
<label for="contact_message">Message*:</label><br />'.@$errors["message"].'
<textarea id="contact_message" name="contact_message" cols="52" rows="7" class="required">'.addslashes(@$_POST["contact_message"]).'</textarea>
</div>
<div>
<input name="submit" class="submit" type="submit" value="Send"/>
</div>
</form>';
}
echo $form;