X-Git-Url: https://git.p6c8.net/form-email.git/blobdiff_plain/f1f62b07946e764d3b51d1da4eeb7aa83702bec6..beba1c3cc4bb271923f1f6d0f14d8a76885cd489:/form-email/mailer.php?ds=inline diff --git a/form-email/mailer.php b/form-email/mailer.php index c85d206..5330f1c 100644 --- a/form-email/mailer.php +++ b/form-email/mailer.php @@ -7,7 +7,7 @@ # geschrieben wurde. # # Autor: Patrick Canterino -# Letzte Aenderung: 7.11.2011 +# Letzte Aenderung: 16.12.2011 # # Copyright (C) 2002-2011 Patrick Canterino # @@ -21,11 +21,13 @@ # Hauptteil # =========== +$VERSION = '3.5-dev'; + require('config.php'); require('functions.php'); require('class.Template.php'); -if($only_post && $_SERVER['REQUEST_METHOD'] != 'POST') show_fatal($err_only_post); +if($_SERVER['REQUEST_METHOD'] != 'POST') show_fatal($err_only_post); # Wenn Captchas aktiviert sind, Session starten @@ -82,13 +84,8 @@ if($subject_max && strlen($subject) > $subject_max) show_user_error($err_subject if($text_max && strlen($text) > $text_max) show_user_error($err_text_long); # Pruefen, ob eingegebene E-Mail-Adresse gueltig ist -# Danke an "ich" aus dem SELFHTML Forum fuer die Muehe - -$mail_regexp = ($no_tld) - ? '/^([a-z0-9]+([\.]?|[-]?|[_]?)?)*([a-z0-9]+([\.]?[_]?)?)@([a-z0-9]+([\.]?|[-]?)?)*[a-z0-9]$/i' - : '/^([a-z0-9]+([\.]?|[-]?|[_]?)?)*([a-z0-9]+([\.]?[_]?)?)@([a-z0-9]+([\.]?|[-]?)?)*[a-z0-9]+\.{1}[a-z]{2,6}$/i'; -if(!preg_match($mail_regexp,$email)) show_user_error($err_invalid_email); +if(!filter_var($email,FILTER_VALIDATE_EMAIL)) show_user_error($err_invalid_email); # Individuelle Felder einlesen @@ -96,20 +93,90 @@ $prepared_user_fields = array(); while(list($user_field,$user_field_data) = each($user_fields)) { $user_field_content = formdata($user_field); + + # Pruefung, ob das Feld gesetzt wurde und ob es optional ist + + if((!$user_field_data['optional']) && (!$user_field_content)) { + show_user_error($user_field_data['errors']['not_set']); + } + elseif($user_field_data['optional'] && (!$user_field_content)) { + # Wenn das Feld optional ist und nicht gesetzt wurde, brechen wir hier ab + # und machen mit dem naechsten Feld weiter + + $prepared_user_fields[$user_field_data['tpl_var']] = ''; + continue; + } + + # Laengen-Pruefung + + if(isset($user_field_data['min']) && $user_field_data['min']) { + if(strlen($user_field_content) < $user_field_data['min']) { + if(isset($user_field_data['errors']['too_short'])) { + show_user_error($user_field_data['errors']['too_short']); + } + else { + show_fatal($err_indiv_errmsg_miss,array('ERRMSG' => 'too_short', 'INDIVIDUAL' => $user_field)); + } + } + } + + if(isset($user_field_data['min']) && $user_field_data['max']) { + if(strlen($user_field_content) > $user_field_data['max']) { + if(isset($user_field_data['errors']['too_long'])) { + show_user_error($user_field_data['errors']['too_long']); + } + else { + show_fatal($err_indiv_errmsg_miss,array('ERRMSG' => 'too_long', 'INDIVIDUAL' => $user_field)); + } + } + } + + # Pruefung gegen frei definierbare Pruef-Funktion if(isset($user_field_data['check']) && $user_field_data['check'] != '') { - if(function_exists($user_field_data['check']) && call_user_func($user_field_data['check'],$user_field_content)) { - show_user_error($user_field_data['errors']['check_fail']); + if(function_exists($user_field_data['check']) && call_user_func($user_field_data['check'],$user_field_content) === false) { + if(isset($user_field_data['errors']['check_fail'])) { + show_user_error($user_field_data['errors']['check_fail']); + } + else { + show_fatal($err_indiv_errmsg_miss,array('ERRMSG' => 'check_fail', 'INDIVIDUAL' => $user_field)); + } } } + + # Pruefung gegen frei definierbaren regulaeren Ausdruck if(isset($user_field_data['regex']) && $user_field_data['regex'] != '') { - if(preg_match($user_field_data['regex'],$user_field_content)) { - show_user_error($user_field_data['errors']['match_fail']); + if(!preg_match($user_field_data['regex'],$user_field_content)) { + if(isset($user_field_data['errors']['match_fail'])) { + show_user_error($user_field_data['errors']['match_fail']); + } + else { + show_fatal($err_indiv_errmsg_miss,array('ERRMSG' => 'match_fail', 'INDIVIDUAL' => $user_field)); + } } } + + # Formularfeld durch frei definierbare Funktion bearbeiten + + if(isset($user_field_data['prepare']) && $user_field_data['prepare'] != '') { + if(function_exists($user_field_data['check'])) { + $user_field_content = call_user_func($user_field_data['prepare'],$user_field_content); + } + } + + # Name der Template-Variable ermitteln + + if(isset($user_field_data['tpl_var']) && $user_field_data['tpl_var'] != '') { + $tpl_var = $user_field_data['tpl_var']; + } + else { + $tpl_var = 'USER_'.$user_field; + } + + # Fertige Formulardaten wegkopieren und fuer spaeter zur Verfuegung stellen - $prepared_user_fields[$user_field_data['tpl_var']] = $user_field_content; + $prepared_user_fields[$tpl_var] = $user_field_content; } # Captcha ueberpruefen @@ -203,7 +270,7 @@ if($add_header) { $header .= 'Content-Type: text/plain; charset="'.$charset.'"'."\n"; $header .= 'Content-Transfer-Encoding: 8bit'."\n"; $header .= 'MIME-Version: 1.0'."\n"; - $header .= 'X-Mailer: Form E-Mail 3.4.1'."\n"; + $header .= 'X-Mailer: Form E-Mail '.$VERSION."\n"; $header .= 'X-Sender-IP: ['.$_SERVER['REMOTE_ADDR'].']'; } else $header .= "Reply-To: $email"; @@ -281,14 +348,15 @@ if($captcha_enable) session_destroy(); if($return_url) { # Per Redirect auf Seite umleiten - if(!preg_match('!://!',$return_url)) { + if(strpos($return_url,'://') === false) { # URL vervollstaendigen $http_host = ($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME']; $protocol = ''; $port = ''; + $path = ''; - if($_SERVER['HTTPS']) { + if(isset($_SERVER['HTTPS'])) { # SSL-verschluesseltes HTTP $protocol = 'https://'; @@ -301,13 +369,13 @@ if($return_url) { if($_SERVER['SERVER_PORT'] != 80) $port = ':'.$_SERVER['SERVER_PORT']; } - if(preg_match('!^/!',$return_url)) { + if(substr($return_url,0,1) == '/') { $return_url = $protocol.$http_host.$port.$return_url; } else { - if(preg_match('!/$!',$_SERVER['SCRIPT_NAME'])) $path = substr($_SERVER['SCRIPT_NAME'],0,-1); + if(substr($_SERVER['SCRIPT_NAME'],-1,1) == '/') $path = substr($_SERVER['SCRIPT_NAME'],0,-1); $path = substr($path,0,strrpos($path,'/')+1); - if(!preg_match('!^/!',$path)) $path = '/'.$path; + if(substr($path,0,1) != '/') $path = '/'.$path; $return_url = $protocol.$http_host.$port.$path.$return_url; }