Forum Moderators: coopster
<?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> "body" : "<!DOCTYPE html>\n<html dir=\"ltr\" lang=\"en\">\n<head>
<title>U heeft zich ingeschreven voor de cursus EHBO en Reanimatie voor kinderen</title></head>\n
<body style=\"background-color: #f9f9f9; padding-left: 11%; padding-top: 7%; padding-right: 2%; max-width: 700px; font-family: Helvetica, Arial;\">\n
<style type=\"text/css\">\nbody {background-color: #f9f9f9;padding-left: 110px;padding-top: 70px; padding-right: 20px;max-width:700px;font-family: Helvetica, Arial;}\np{font-size: 12px; color: #666666;}\nh2{font-size: 28px !important;color: #666666 ! important;margin: 0px; border-bottom: 1px dotted #00A2FF; padding-bottom:3px;}\ntable{width:80%;}\ntd {font-size: 12px !important; line-height: 30px;color: #666666 !important; margin: 0px;border-bottom: 1px solid #e9e9e9;}\ntd:first-child {font-size: 13px !important; font-weight:bold; color: #333 !important; vertical-align:text-top; min-width:10%; padding-right:5px;}\na:link {color:#666666; text-decoration:underline;} a:visited {color:#666666; text-decoration:none;} a:hover {color:#00A2FF;}\nb{font-weight: bold;}\n</style>\n<h2 style=\"font-size: 22px !important;color: #666666 ! important;margin: 0px; border-bottom: 1px dotted #00A2FF; padding-bottom:3px;\">Wij danken u voor uw inschrijving kinder EHBO en Reanimatie cursus.. <br/>Hieronder treft u de gegevens aan zoals deze door u zijn opgegeven:</h2>\n<div>\n[i][_form_results_][/i]\n<br />\n<p>U bent akkoord gegaan met de algemene voorwaarden. Deze kunt u hier downloaden. http://example.com/documenten/algemene_voorwaarden.pdf </p>\n</div>\n</body>\n</html>\n" [edited by: eelixduppy at 4:29 pm (utc) on Aug 7, 2013]
[edit reason] exemplified url [/edit]
$headers = "From: admin@example.com\r\n"
.= "Reply-to: admin@example.com\r\n"
.= "Content-type: text/html; charset=ISO-8859-1";
$to = 'me@mysite.com';
$subject = 'A HTML Email';
$body = '<br><br><br><span style="color: #0000ff;">Some blue text!</span>';
mail($to, $subject, $body, $headers);