<?php\r
\r
#\r
-# Form E-Mail 3.4.1\r
+# Form E-Mail 3.5\r
#\r
# Versenden einer E-Mail, die ueber ein Kontaktformular\r
# geschrieben wurde.\r
#\r
# Autor: Patrick Canterino <patrick@patshaping.de>\r
-# Letzte Aenderung: 24.2.2011\r
+# Letzte Aenderung: 17.12.2011\r
#\r
# Copyright (C) 2002-2011 Patrick Canterino\r
#\r
-# Diese Datei kann unter den Bedingungen der "Artistic License 1.0"\r
+# Diese Datei kann unter den Bedingungen der "Artistic License 2.0"\r
# weitergegeben und / oder veraendert werden.\r
# Siehe:\r
-# http://www.opensource.org/licenses/artistic-license-1.0.php\r
+# http://www.opensource.org/licenses/artistic-license-2.0\r
#\r
\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
-if($captcha_enable)\r
-{\r
- session_start();\r
+if($captcha_enable) {\r
+ session_start();\r
\r
- # Pruefen, ob die zulaessige Zahl der Falscheingaben bei Captchas ueberschritten wurde\r
+ # Pruefen, ob die zulaessige Zahl der Falscheingaben bei Captchas ueberschritten wurde\r
\r
- if($captcha_max && isset($_SESSION['captcha_failed']) && $_SESSION['captcha_failed'] >= $captcha_max)\r
- {\r
- show_fatal($err_captcha_max);\r
- }\r
+ if($captcha_max && isset($_SESSION['captcha_failed']) && $_SESSION['captcha_failed'] >= $captcha_max) {\r
+ show_fatal($err_captcha_max);\r
+ }\r
}\r
\r
# Bestimmte Werte in Integers umwandeln\r
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
+if(!filter_var($email,FILTER_VALIDATE_EMAIL)) show_user_error($err_invalid_email);\r
+\r
+# Individuelle Felder einlesen\r
+\r
+$prepared_user_fields = array();\r
+\r
+while(list($user_field,$user_field_data) = each($user_fields)) {\r
+ $user_field_content = formdata($user_field);\r
+\r
+ # Pruefung, ob das Feld gesetzt wurde und ob es optional ist\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
+ $prepared_user_fields[$user_field_data['tpl_var']] = '';\r
+ continue;\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
+ 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
+ # 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
+ 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
+ # Formularfeld durch frei definierbare Funktion bearbeiten\r
+\r
+ if(isset($user_field_data['prepare']) && $user_field_data['prepare'] != '') {\r
+ if(function_exists($user_field_data['check'])) {\r
+ $user_field_content = call_user_func($user_field_data['prepare'],$user_field_content);\r
+ }\r
+ }\r
+\r
+ # Name der Template-Variable ermitteln\r
\r
-if(!preg_match($mail_regexp,$email)) show_user_error($err_invalid_email);\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[$tpl_var] = $user_field_content;\r
+}\r
\r
# Captcha ueberpruefen\r
\r
-if($captcha_enable)\r
-{\r
- $captcha_input = formdata('captcha');\r
- $captcha_incorrect = false;\r
-\r
- if(isset($_SESSION) && isset($_SESSION['captcha']))\r
- {\r
- if($captcha_case)\r
- {\r
- if(!$captcha_input || empty($captcha_input) || $captcha_input != $_SESSION['captcha']) $captcha_incorrect = true;\r
- }\r
- else\r
- {\r
- if(!$captcha_input || empty($captcha_input) || strtolower($captcha_input) != strtolower($_SESSION['captcha'])) $captcha_incorrect = true;\r
- }\r
- \r
- if($captcha_incorrect)\r
- {\r
- if($captcha_max)\r
- {\r
- if(isset($_SESSION['captcha_failed']) && $_SESSION['captcha_failed'])\r
- {\r
- $_SESSION['captcha_failed']++;\r
+if($captcha_enable) {\r
+ $captcha_input = formdata('captcha');\r
+ $captcha_incorrect = false;\r
+\r
+ if(isset($_SESSION) && isset($_SESSION['captcha'])) {\r
+ if($captcha_case) {\r
+ if(!$captcha_input || empty($captcha_input) || $captcha_input != $_SESSION['captcha']) $captcha_incorrect = true;\r
+ }\r
+ else {\r
+ if(!$captcha_input || empty($captcha_input) || strtolower($captcha_input) != strtolower($_SESSION['captcha'])) $captcha_incorrect = true;\r
+ }\r
+\r
+ if($captcha_incorrect) {\r
+ if($captcha_max) {\r
+ if(isset($_SESSION['captcha_failed']) && $_SESSION['captcha_failed']) {\r
+ $_SESSION['captcha_failed']++;\r
+ }\r
+ else {\r
+ $_SESSION['captcha_failed'] = 1;\r
+ }\r
+ }\r
+\r
+ if($captcha_max && isset($_SESSION['captcha_failed']) && $_SESSION['captcha_failed'] >= $captcha_max) {\r
+ show_fatal($err_captcha_max);\r
+ }\r
+ else {\r
+ show_user_error($err_captcha_incorrect);\r
+ }\r
+ }\r
}\r
- else\r
- {\r
- $_SESSION['captcha_failed'] = 1;\r
+ else {\r
+ show_fatal($err_captcha_session_failure);\r
}\r
- }\r
-\r
- if($captcha_max && isset($_SESSION['captcha_failed']) && $_SESSION['captcha_failed'] >= $captcha_max)\r
- {\r
- show_fatal($err_captcha_max);\r
- }\r
- else\r
- { \r
- show_user_error($err_captcha_incorrect);\r
- }\r
- }\r
- }\r
- else\r
- {\r
- show_fatal($err_captcha_session_failure);\r
- }\r
}\r
\r
# Referer ueberpruefen\r
\r
-if($check_referer)\r
-{\r
- $referer_ok = semicolon_split($referer_ok);\r
+if($check_referer) {\r
+ $referer_ok = semicolon_split($referer_ok);\r
\r
- $referer_parts = parse_url($_SERVER['HTTP_REFERER']);\r
- $referer_host = $referer_parts['host'];\r
+ $referer_parts = parse_url($_SERVER['HTTP_REFERER']);\r
+ $referer_host = $referer_parts['host'];\r
\r
- if(in_array($referer_host,$referer_ok) === false) show_fatal($err_referer_not_ok);\r
+ if(in_array($referer_host,$referer_ok) === false) show_fatal($err_referer_not_ok);\r
}\r
\r
# Zeilenumbrueche in Namen und Betreff durch Leerzeichen ersetzen\r
\r
$header = '';\r
\r
-if($friendly_sender)\r
-{\r
- if($friendly_sender == 2)\r
- {\r
- if(preg_match("/[\200-\377]/",$name))\r
- {\r
- # Absendernamen mit Base64 codieren\r
-\r
- $encoded_name = base64_encode($name);\r
- $encoded_name = wordwrap($encoded_name,56,"\015\012",1);\r
- $encoded_name = "=?$charset?B?$encoded_name?=";\r
- $encoded_name = str_replace("\015\012","?=\015\012 =?$charset?B?",$encoded_name);\r
- }\r
- else\r
- {\r
- # Bestimmte Zeichen im Absendernamen codieren\r
-\r
- $encoded_name = str_replace('"','\"',$name);\r
- $encoded_name = str_replace('(','\\(',$encoded_name);\r
- $encoded_name = str_replace(')','\\)',$encoded_name);\r
- $encoded_name = '"'.$encoded_name.'"';\r
- }\r
-\r
- $header = "From: $encoded_name <$email>\n";\r
- }\r
- else $header = "From: $email\n";\r
+if($friendly_sender) {\r
+ if($friendly_sender == 2) {\r
+ if(preg_match("/[\200-\377]/",$name)) {\r
+ # Absendernamen mit Base64 codieren\r
+\r
+ $encoded_name = base64_encode($name);\r
+ $encoded_name = wordwrap($encoded_name,56,"\015\012",1);\r
+ $encoded_name = "=?$charset?B?$encoded_name?=";\r
+ $encoded_name = str_replace("\015\012","?=\015\012 =?$charset?B?",$encoded_name);\r
+ }\r
+ else {\r
+ # Bestimmte Zeichen im Absendernamen codieren\r
+\r
+ $encoded_name = str_replace('"','\"',$name);\r
+ $encoded_name = str_replace('(','\\(',$encoded_name);\r
+ $encoded_name = str_replace(')','\\)',$encoded_name);\r
+ $encoded_name = '"'.$encoded_name.'"';\r
+ }\r
+\r
+ $header = "From: $encoded_name <$email>\n";\r
+ }\r
+ else $header = "From: $email\n";\r
}\r
\r
-if($add_header)\r
-{\r
- if(!$friendly_sender) $header .= "Reply-To: $email\n";\r
- $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-Sender-IP: ['.$_SERVER['REMOTE_ADDR'].']';\r
+if($add_header) {\r
+ if(!$friendly_sender) $header .= "Reply-To: $email\n";\r
+ $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 '.$VERSION."\n";\r
+ $header .= 'X-Sender-IP: ['.$_SERVER['REMOTE_ADDR'].']';\r
}\r
else $header .= "Reply-To: $email";\r
\r
# Betreff mit Base64 codieren, wenn er Zeichen enthaelt,\r
# die nicht aus dem ASCII-Zeichensatz stammen\r
\r
-if(preg_match("/[\200-\377]/",$subject))\r
-{\r
- $encoded_subject = base64_encode($subject);\r
- $encoded_subject = wordwrap($encoded_subject,56,"\015\012",1);\r
- $encoded_subject = "=?$charset?B?$encoded_subject?=";\r
- $encoded_subject = str_replace("\015\012","?=\015\012 =?$charset?B?",$encoded_subject);\r
+if(preg_match("/[\200-\377]/",$subject)) {\r
+ $encoded_subject = base64_encode($subject);\r
+ $encoded_subject = wordwrap($encoded_subject,56,"\015\012",1);\r
+ $encoded_subject = "=?$charset?B?$encoded_subject?=";\r
+ $encoded_subject = str_replace("\015\012","?=\015\012 =?$charset?B?",$encoded_subject);\r
}\r
else $encoded_subject = $subject;\r
\r
$mtpl->set_var('SUBJECT',$subject);\r
$mtpl->set_var('TIME', $time);\r
\r
-# ... Umgebungsvariablen einfuegen\r
-\r
-if(isset($allowed_envs) && is_array($allowed_envs))\r
-{\r
- foreach($allowed_envs as $allowed_env)\r
- {\r
- if(isset($_SERVER[$allowed_env]))\r
- {\r
- $mtpl->set_var('ENV_'.$allowed_env,$_SERVER[$allowed_env]);\r
- }\r
- else\r
- {\r
- $mtpl->set_var('ENV_'.$allowed_env,'');\r
- }\r
- }\r
+# ... Umgebungsvariablen einfuegen...\r
+\r
+if(isset($allowed_envs) && is_array($allowed_envs)) {\r
+ foreach($allowed_envs as $allowed_env) {\r
+ if(isset($_SERVER[$allowed_env])) {\r
+ $mtpl->set_var('ENV_'.$allowed_env,$_SERVER[$allowed_env]);\r
+ }\r
+ else {\r
+ $mtpl->set_var('ENV_'.$allowed_env,'');\r
+ }\r
+ }\r
+}\r
+\r
+# ... eigene Felder einfuegen\r
+\r
+while(list($tpl_var,$user_field_content) = each($prepared_user_fields)) {\r
+ $mtpl->set_var($tpl_var,$user_field_content);\r
}\r
\r
$mtpl->set_var('TEXT',$text);\r
\r
# ... und die Mail abschicken (bei einem Fehler erscheint eine Meldung)\r
\r
-if($recipient && is_array($aliases) && $aliases[$recipient])\r
-{\r
- # Empfaenger mit Alias-Namen\r
+if($recipient && is_array($aliases) && $aliases[$recipient]) {\r
+ # Empfaenger mit Alias-Namen\r
\r
- $mailto = $aliases[$recipient];\r
+ $mailto = $aliases[$recipient];\r
}\r
\r
$mailto = semicolon_split($mailto);\r
\r
-for($x=0;$x<count($mailto);$x++)\r
-{\r
- mail($mailto[$x],$encoded_subject,$mailtext,$header) or die($err_send_error);\r
+for($x=0;$x<count($mailto);$x++) {\r
+ mail($mailto[$x],$encoded_subject,$mailtext,$header) or die($err_send_error);\r
}\r
\r
if($captcha_enable) session_destroy();\r
\r
# Mail wurde erfolgreich versendet, also wird die Dankesseite angezeigt\r
\r
-if($return_url)\r
-{\r
- # Per Redirect auf Seite umleiten\r
-\r
- if(!preg_match('!://!',$return_url))\r
- {\r
- # URL vervollstaendigen\r
-\r
- $http_host = ($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];\r
- $protocol = '';\r
- $port = '';\r
-\r
- if($_SERVER['HTTPS'])\r
- {\r
- # SSL-verschluesseltes HTTP\r
-\r
- $protocol = 'https://';\r
- if($_SERVER['SERVER_PORT'] != 443) $port = ':'.$_SERVER['SERVER_PORT'];\r
- }\r
- else\r
- {\r
- # Normales HTTP\r
-\r
- $protocol = 'http://';\r
- if($_SERVER['SERVER_PORT'] != 80) $port = ':'.$_SERVER['SERVER_PORT'];\r
- }\r
-\r
- if(preg_match('!^/!',$return_url))\r
- {\r
- $return_url = $protocol.$http_host.$port.$return_url;\r
- }\r
- else\r
- {\r
- if(preg_match('!/$!',$_SERVER['SCRIPT_NAME'])) $path = substr($_SERVER['SCRIPT_NAME'],0,-1);\r
- $path = substr($path,0,strrpos($path,'/')+1);\r
- if(!preg_match('!^/!',$path)) $path = '/'.$path;\r
-\r
- $return_url = $protocol.$http_host.$port.$path.$return_url;\r
- }\r
- }\r
-\r
- header('Status: 303 See Other');\r
- header('Location: '.$return_url);\r
+if($return_url) {\r
+ # Per Redirect auf Seite umleiten\r
+\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(isset($_SERVER['HTTPS'])) {\r
+ # SSL-verschluesseltes HTTP\r
+\r
+ $protocol = 'https://';\r
+ if($_SERVER['SERVER_PORT'] != 443) $port = ':'.$_SERVER['SERVER_PORT'];\r
+ }\r
+ else {\r
+ # Normales HTTP\r
+\r
+ $protocol = 'http://';\r
+ if($_SERVER['SERVER_PORT'] != 80) $port = ':'.$_SERVER['SERVER_PORT'];\r
+ }\r
+\r
+ if(substr($return_url,0,1) == '/') {\r
+ $return_url = $protocol.$http_host.$port.$return_url;\r
+ }\r
+ else {\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(substr($path,0,1) != '/') $path = '/'.$path;\r
+\r
+ $return_url = $protocol.$http_host.$port.$path.$return_url;\r
+\r
+ die($return_url);\r
+ }\r
+ }\r
+\r
+ header('Status: 303 See Other');\r
+ header('Location: '.$return_url);\r
}\r
-else\r
-{\r
- # Mit Template formatierte Seite anzeigen\r
+else {\r
+ # Mit Template formatierte Seite anzeigen\r
\r
- $stpl = new Template;\r
- $stpl->read_file($tpl_sent);\r
+ $stpl = new Template;\r
+ $stpl->read_file($tpl_sent);\r
\r
- $stpl->set_var('EMAIL', plain($email));\r
- $stpl->set_var('MAIL', plain($mailtext));\r
- $stpl->set_var('NAME', plain($name));\r
- $stpl->set_var('SUBJECT',plain($subject));\r
- $stpl->set_var('TEXT', plain($text));\r
- $stpl->set_var('TIME', plain($time));\r
+ $stpl->set_var('EMAIL', plain($email));\r
+ $stpl->set_var('MAIL', plain($mailtext));\r
+ $stpl->set_var('NAME', plain($name));\r
+ $stpl->set_var('SUBJECT',plain($subject));\r
+ $stpl->set_var('TEXT', plain($text));\r
+ $stpl->set_var('TIME', plain($time));\r
\r
- $stpl->parse();\r
+ $stpl->parse();\r
\r
- print $stpl->get_template();\r
+ print $stpl->get_template();\r
}\r
\r
#\r