]> git.p6c8.net - form-email.git/blobdiff - form-email/mailer.php
Debug-Code entfernt...
[form-email.git] / form-email / mailer.php
index bed4207d6b2bf30b326f0f6a403084e0735e8f31..32f1caa545fb493a0372c702ae184dc77cb3540c 100644 (file)
@@ -7,7 +7,7 @@
 # geschrieben wurde.\r
 #\r
 # Autor:            Patrick Canterino <patrick@patshaping.de>\r
-# Letzte Aenderung: 3.12.2011\r
+# Letzte Aenderung: 17.12.2011\r
 #\r
 # Copyright (C) 2002-2011 Patrick Canterino\r
 #\r
 #  Hauptteil\r
 # ===========\r
 \r
+$VERSION = '3.5-dev';\r
+\r
 require('config.php');\r
 require('functions.php');\r
 require('class.Template.php');\r
 \r
-if($only_post && $_SERVER['REQUEST_METHOD'] != 'POST') show_fatal($err_only_post);\r
+if($_SERVER['REQUEST_METHOD'] != 'POST') show_fatal($err_only_post);\r
 \r
 # Wenn Captchas aktiviert sind, Session starten\r
 \r
@@ -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);\r
 \r
 # Pruefen, ob eingegebene E-Mail-Adresse gueltig ist\r
-# Danke an "ich" aus dem SELFHTML Forum fuer die Muehe\r
-\r
-$mail_regexp = ($no_tld)\r
-             ? '/^([a-z0-9]+([\.]?|[-]?|[_]?)?)*([a-z0-9]+([\.]?[_]?)?)@([a-z0-9]+([\.]?|[-]?)?)*[a-z0-9]$/i'\r
-             : '/^([a-z0-9]+([\.]?|[-]?|[_]?)?)*([a-z0-9]+([\.]?[_]?)?)@([a-z0-9]+([\.]?|[-]?)?)*[a-z0-9]+\.{1}[a-z]{2,6}$/i';\r
 \r
-if(!preg_match($mail_regexp,$email)) show_user_error($err_invalid_email);\r
+if(!filter_var($email,FILTER_VALIDATE_EMAIL)) show_user_error($err_invalid_email);\r
 \r
 # Individuelle Felder einlesen\r
 \r
@@ -96,36 +93,70 @@ $prepared_user_fields = array();
 \r
 while(list($user_field,$user_field_data) = each($user_fields)) {\r
     $user_field_content = formdata($user_field);\r
-    \r
+\r
     # Pruefung, ob das Feld gesetzt wurde und ob es optional ist\r
-    \r
+\r
     if((!$user_field_data['optional']) && (!$user_field_content)) {\r
         show_user_error($user_field_data['errors']['not_set']);\r
     }\r
     elseif($user_field_data['optional'] && (!$user_field_content)) {\r
         # Wenn das Feld optional ist und nicht gesetzt wurde, brechen wir hier ab\r
         # und machen mit dem naechsten Feld weiter\r
-        \r
+\r
         $prepared_user_fields[$user_field_data['tpl_var']] = '';\r
         continue;\r
     }\r
-    \r
+\r
+    # Laengen-Pruefung\r
+\r
+    if(isset($user_field_data['min']) && $user_field_data['min']) {\r
+        if(strlen($user_field_content) < $user_field_data['min']) {\r
+            if(isset($user_field_data['errors']['too_short'])) {\r
+                show_user_error($user_field_data['errors']['too_short']);\r
+            }\r
+            else {\r
+                show_fatal($err_indiv_errmsg_miss,array('ERRMSG' => 'too_short', 'INDIVIDUAL' => $user_field));\r
+            }\r
+        }\r
+    }\r
+\r
+    if(isset($user_field_data['min']) && $user_field_data['max']) {\r
+        if(strlen($user_field_content) > $user_field_data['max']) {\r
+            if(isset($user_field_data['errors']['too_long'])) {\r
+                show_user_error($user_field_data['errors']['too_long']);\r
+            }\r
+            else {\r
+                show_fatal($err_indiv_errmsg_miss,array('ERRMSG' => 'too_long', 'INDIVIDUAL' => $user_field));\r
+            }\r
+        }\r
+    }\r
+\r
     # Pruefung gegen frei definierbare Pruef-Funktion\r
 \r
     if(isset($user_field_data['check']) && $user_field_data['check'] != '') {\r
         if(function_exists($user_field_data['check']) && call_user_func($user_field_data['check'],$user_field_content) === false) {\r
-            show_user_error($user_field_data['errors']['check_fail']);\r
+            if(isset($user_field_data['errors']['check_fail'])) {\r
+                show_user_error($user_field_data['errors']['check_fail']);\r
+            }\r
+            else {\r
+                show_fatal($err_indiv_errmsg_miss,array('ERRMSG' => 'check_fail', 'INDIVIDUAL' => $user_field));\r
+            }\r
         }\r
     }\r
-    \r
+\r
     # Pruefung gegen frei definierbaren regulaeren Ausdruck\r
 \r
     if(isset($user_field_data['regex']) && $user_field_data['regex'] != '') {\r
         if(!preg_match($user_field_data['regex'],$user_field_content)) {\r
-            show_user_error($user_field_data['errors']['match_fail']);\r
+            if(isset($user_field_data['errors']['match_fail'])) {\r
+                show_user_error($user_field_data['errors']['match_fail']);\r
+            }\r
+            else {\r
+                show_fatal($err_indiv_errmsg_miss,array('ERRMSG' => 'match_fail', 'INDIVIDUAL' => $user_field));\r
+            }\r
         }\r
     }\r
-    \r
+\r
     # Formularfeld durch frei definierbare Funktion bearbeiten\r
 \r
     if(isset($user_field_data['prepare']) && $user_field_data['prepare'] != '') {\r
@@ -133,10 +164,19 @@ while(list($user_field,$user_field_data) = each($user_fields)) {
             $user_field_content = call_user_func($user_field_data['prepare'],$user_field_content);\r
         }\r
     }\r
-    \r
+\r
+    # Name der Template-Variable ermitteln\r
+\r
+    if(isset($user_field_data['tpl_var']) && $user_field_data['tpl_var'] != '') {\r
+        $tpl_var = $user_field_data['tpl_var'];\r
+    }\r
+    else {\r
+        $tpl_var = 'USER_'.$user_field;\r
+    }\r
+\r
     # Fertige Formulardaten wegkopieren und fuer spaeter zur Verfuegung stellen\r
 \r
-    $prepared_user_fields[$user_field_data['tpl_var']] = $user_field_content;\r
+    $prepared_user_fields[$tpl_var] = $user_field_content;\r
 }\r
 \r
 # Captcha ueberpruefen\r
@@ -152,7 +192,7 @@ if($captcha_enable) {
         else {\r
             if(!$captcha_input || empty($captcha_input) || strtolower($captcha_input) != strtolower($_SESSION['captcha'])) $captcha_incorrect = true;\r
         }\r
-  \r
+\r
         if($captcha_incorrect) {\r
             if($captcha_max) {\r
                 if(isset($_SESSION['captcha_failed']) && $_SESSION['captcha_failed']) {\r
@@ -166,7 +206,7 @@ if($captcha_enable) {
             if($captcha_max && isset($_SESSION['captcha_failed']) && $_SESSION['captcha_failed'] >= $captcha_max) {\r
                 show_fatal($err_captcha_max);\r
             }\r
-            else {   \r
+            else {\r
                 show_user_error($err_captcha_incorrect);\r
             }\r
         }\r
@@ -230,7 +270,7 @@ if($add_header) {
     $header .= 'Content-Type: text/plain; charset="'.$charset.'"'."\n";\r
     $header .= 'Content-Transfer-Encoding: 8bit'."\n";\r
     $header .= 'MIME-Version: 1.0'."\n";\r
-    $header .= 'X-Mailer: Form E-Mail 3.4.1'."\n";\r
+    $header .= 'X-Mailer: Form E-Mail '.$VERSION."\n";\r
     $header .= 'X-Sender-IP: ['.$_SERVER['REMOTE_ADDR'].']';\r
 }\r
 else $header .= "Reply-To: $email";\r
@@ -308,14 +348,15 @@ if($captcha_enable) session_destroy();
 if($return_url) {\r
     # Per Redirect auf Seite umleiten\r
 \r
-    if(!preg_match('!://!',$return_url)) {\r
+    if(strpos($return_url,'://') === false) {\r
         # URL vervollstaendigen\r
 \r
         $http_host = ($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];\r
         $protocol  = '';\r
         $port      = '';\r
+        $path      = '';\r
 \r
-        if($_SERVER['HTTPS']) {\r
+        if(isset($_SERVER['HTTPS'])) {\r
             # SSL-verschluesseltes HTTP\r
 \r
             $protocol = 'https://';\r
@@ -328,13 +369,19 @@ if($return_url) {
             if($_SERVER['SERVER_PORT'] != 80) $port = ':'.$_SERVER['SERVER_PORT'];\r
         }\r
 \r
-        if(preg_match('!^/!',$return_url)) {\r
+        if(substr($return_url,0,1) == '/') {\r
             $return_url = $protocol.$http_host.$port.$return_url;\r
         }\r
         else {\r
-            if(preg_match('!/$!',$_SERVER['SCRIPT_NAME'])) $path = substr($_SERVER['SCRIPT_NAME'],0,-1);\r
+            if(substr($_SERVER['SCRIPT_NAME'],-1,1) == '/') {\r
+                $path = substr($_SERVER['SCRIPT_NAME'],0,-1);\r
+            }\r
+            else {\r
+                $path = $_SERVER['SCRIPT_NAME'];\r
+            }\r
+\r
             $path = substr($path,0,strrpos($path,'/')+1);\r
-            if(!preg_match('!^/!',$path)) $path = '/'.$path;\r
+            if(substr($path,0,1) != '/') $path = '/'.$path;\r
 \r
             $return_url = $protocol.$http_host.$port.$path.$return_url;\r
         }\r

patrick-canterino.de