Here is a part of my php script
<?php
// Set email variables
$email = $_POST['email'];
$email_to = 'xxxxxxxxxxxxxx@xxxxxxxxxxxxx.xxxxxx';
$email_subject = 'Inschrijving EHBO cursus';
$email_subject_user = 'U bent ingeschreven voor de cursus EHBO en reanimatie aan kinderen';
// Set required fields
$required_fields = array('naam','email','emailControle','telefoon','algemene_voorwaarden');
// set error messages
$error_messages = array(
'naam' => 'Geef uw naam op svp!',
'email' => 'Geef een geldig email op!',
'emailControle' => 'Uw email adres komt niet overeen!',
'telefoon' => 'Geef uw telefoon nummer op svp!',
'algemene_voorwaarden' => 'U moet accoord gaan met de algemene voorwaarden.'
);
// Set form status
$form_complete = FALSE;
// configure validation array
$validation = array();
// check form submittal
if(!empty($_POST)) {
// Sanitise POST array
foreach($_POST as $key => $value) $_POST[$key] = remove_email_injection(trim($value));
// Loop into required fields and make sure they match our needs
foreach($required_fields as $field) {
// the field has been submitted?
if(!array_key_exists($field, $_POST)) array_push($validation, $field);
// check there is information in the field?
if($_POST[$field] == '') array_push($validation, $field);
// validate the email address supplied
if($field == 'email') if(!validate_email_address($_POST[$field])) array_push($validation, $field);
//Eigen opbouw van email check
if ($field == 'emailControle') if($_POST[$field] != $_POST['email']) array_push($validation, $field);
}
//einde eigen opbouw email check
//telefoon check
if (!ctype_digit($_POST['telefoon']) || strlen($_POST['telefoon']) != 10) array_push($validation, $field);
//algemene voorwaarden check
if ($field == 'algemene_voorwaarden') if (!isset ($_POST['algemene_voorwaarden'])) array_push($validation, $field);
// basic validation result
if(count($validation) == 0) {
// Prepare our content string
$email_content = 'Inschrijving EHBO cursus: ' . "\n\n";
$email_content_user = 'Gefeliciteerd met uw inschrijving voor de cursus EHBO en Reanimatie aan kinderen: '. "\n\n";
// simple email content
foreach($_POST as $key => $value) {
if($key != 'submit') $email_content .= $key . ': ' . $value . "\n\n";
if($key != 'submit') $email_content_user .= $key . ': ' . $value . "\n\n";
}
// if validation passed ok then send the email
mail($email_to, $email_subject, $email_content . '', 'From: ' . $email);
// if validation passed ok then send the email to user
mail($email, $email_subject_user, $email_content_user . '', 'From: ' . $email_to);
// Update form switch
$form_complete = TRUE;
}
}
function validate_email_address($email = FALSE) {
return (preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i', $email))? TRUE : FALSE;
}
function remove_email_injection($field = FALSE) {
return (str_ireplace(array("\r", "\n", "%0a", "%0d", "Content-Type:", "bcc:","to:","cc:"), '', $field));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Kunt U het leven van een kind redden? Nee! Volg dan nu een EHBO cursus.</title>