FormEMailer V4.0

This Extension installs a new Object in a new tab of the object palette, which sends a form content via email - it provides consistency checks, does encode foreign languages and has a security check.

Installation:

Further Instructions can be found in the ReadMe.txt.

Copyright:

(c)2002, Oliver Michalak / werk01.de

History:

V4:

V3:

V2:

V1.2:

V1.1:

V1.0:


Module Definition:

Scripts:

Icons:

Specs:

Interface:

"your@email.com" /* TO */, "FROM" => "{from}" /* FROM */, "SUBJECT" => "{subject}" /* SUBJECT */, "SUBMIT" => "submit" /* SUBMIT */, "CHECK" => "from,subject,text" /* CHECK */, "SUCCESS" => "Message send to {to}." /* SUCCESS */, "ERROR" => "Input error, please check your input." /* ERROR */, "REFERER" => "werk01.de" /* REFERER */, "FIELD_NAMES" => "true" /* FIELD_NAMES" */, "FILES" => "0" /* FILES */, "FILE_MAX" => "100" /* FILE_MAX */, "FILE_TYPE" => "pdf,jpg,gif" /* FILE_TYPE */, "EXCLUDE_NAMES" => "PHPSESSID,sid" /* EXCLUDE_NAMES */, "FILE_HTML" => "page.txt" /* FILE_HTML */); if (!function_exists("form_parse")) { function form_parse ($post, $init, $except) { $val = $init; foreach ($post as $key => $value) if ($key != $except) $val = str_replace ("{".$key."}", str_replace (array ("\\r", "\\n"), "", trim(stripslashes($value))), $val); return $val; } } if (!function_exists("fe_utf8_decode")) { function fe_utf8_decode ($in) { $result = utf8_decode(str_replace ("?", "q0u0e0s0t0i0o0n", $in)); if (strpos($result, "?") !== false) return $in; else return str_replace("q0u0e0s0t0i0o0n", "?", $result); } } if (!function_exists("fe_qp_encode")) { function fe_qp_encode ($input, $line_max=76) { $lines = preg_split("/\r?\n/", $input); $output = ""; foreach ($lines as $line) { $linelen = strlen($line); $newline = ""; for ($i = 0; $i < $linelen; $i++) { $char = substr($line, $i, 1); $dec = ord($char); if (($dec == 32) AND ($i == ($linelen - 1))) $char = "=20"; elseif ($dec == 9) ; elseif (($dec == 61) OR ($dec < 32 ) OR ($dec > 126)) $char = "=".strtoupper(sprintf("%02s", dechex($dec))); if ((strlen($newline) + strlen($char)) >= $line_max) { $output .= "$newline=\n"; $newline = ""; } $newline .= $char; } $output .= "$newline\n"; } return substr($output, 0, -1); } } $valid = true; if (strlen($fe_data["REFERER"])) { if (isset($_SERVER)) $fe_server = $_SERVER; else $fe_server = $HTTP_SERVER_VARS; $fe_ref = @parse_url ($fe_server["HTTP_REFERER"]); if (isset($fe_server["HTTP_REFERER"]) && substr($fe_ref["host"], -strlen($fe_data["REFERER"])) != $fe_data["REFERER"]) $valid = false; } if (isset($_POST)) $fe_post = $_POST; else $fe_post = $HTTP_POST_VARS; if ($valid && isset($fe_post[$fe_data["SUBMIT"]])) { if (strlen($fe_data["CHECK"])) { $fe_chk = split (",", $fe_data["CHECK"]); foreach ($fe_chk as $fe_act) { if (!strlen($fe_post[$fe_act])) { $valid = false; break; } } } $fe_to = form_parse ($fe_post, $fe_data["TO"], $fe_data["SUBMIT"]); if ($valid && strlen($fe_to) && preg_match ("/^[._a-zA-Z0-9-]{1,}@{1}[.a-zA-Z0-9-]{2,}.{1}[a-zA-Z]{2,5}$/", $fe_to)) { $fe_from = form_parse ($fe_post, $fe_data["FROM"], $fe_data["SUBMIT"]); $fe_header = array("Content-Transfer-Encoding" => "quoted-printable", "Content-Type" => "text/plain; charset=ISO-8859-1"); if (strlen($fe_from)) $fe_header["From"] = $fe_header["Reply-To"] = $fe_from; $fe_subject = form_parse ($fe_post, $fe_data["SUBJECT"], $fe_data["SUBMIT"]); if (strlen($fe_subject)) { $fe_sub2 = fe_qp_encode(fe_utf8_decode($fe_subject), 1000); if (strlen($fe_sub2) != strlen($fe_subject)) $fe_subject = "=?ISO-8859-1?Q?$fe_sub2?="; } $fe_mess = "\n"; $fe_exclude = split ("," ,$fe_data["EXCLUDE_NAMES"]); foreach ($fe_post as $key => $value) { if (is_array ($fe_exclude) && in_array ($key, $fe_exclude)) continue; if ($key != $fe_data["SUBMIT"] && !preg_match ("/^\W*(to|resent-to|cc|resent-cc|bcc|resent-bcc|content-type)\W*:/i", $key.":")) { if ($fe_data["FIELD_NAMES"] == "true") $fe_mess .= "$key:\n"; $fe_mess .= stripslashes($value)."\n\n"; } } $fe_mess = fe_qp_encode(fe_smart_decode($fe_mess)); if (isset($HTTP_POST_FILES)) $fe_files = $HTTP_POST_FILES; if (isset($_FILES)) $fe_files = $_FILES; if (1 == $fe_data["FILES"] && isset($fe_files)) { if (strlen($fe_data["FILE_TYPE"])) $fe_types = explode (",", $fe_data["FILE_TYPE"]); foreach ($fe_files as $fe_act) { if (!strlen($fe_act["tmp_name"]) || !file_exists ($fe_act["tmp_name"])) continue; if (strlen($fe_data["FILE_MAX"]) && $fe_data["FILE_MAX"]*1024 < $fe_act["size"]) continue; $fe_act_type = strtolower(substr ($fe_act["name"], strrpos ($fe_act["name"], ".")+1)); if (count($fe_types) && !in_array ($fe_act_type, $fe_types)) continue; if (!isset($fe_id)) { $fe_id = "=_".md5(uniqid(time())); $fe_header["Mime-Version"] = "1.0"; $fe_header["Content-Type"] = "multipart/mixed; boundary=\"$fe_id\""; $fe_mess = "--$fe_id\nContent-Transfer-Encoding: quoted-printable\nContent-Type: text/plain; charset=ISO-8859-1\n\n$fe_mess\n"; } $fe_mess .= "--$fe_id\nContent-Disposition: attachment; filename=\"".$fe_act["name"]."\"\nContent-Type: ".$fe_act["type"]."; name=\"".$fe_act["name"]."\"\nContent-Transfer-Encoding: base64\n\n"; $fe_mess .= chunk_split (base64_encode (implode ("", @file ($fe_act["tmp_name"]))))."\n\n"; } if (isset($fe_id)) $fe_mess .= "--$fe_id--"; unset ($fe_types, $fe_act_type, $fe_act, $fe_id, $fe_files); } if (2 == $fe_data["FILES"]) { if (substr($fe_data["FILE_HTML"], 0, 1) == "/") $fe_htmlfile = substr($_SERVER["DOCUMENT_ROOT"],0,-1).$fe_data["FILE_HTML"]; else $fe_htmlfile = substr($_SERVER["DOCUMENT_ROOT"],0,-1).dirname($_SERVER['PHP_SELF'])."/".$fe_data["FILE_HTML"]; if (file_exists($fe_htmlfile)) { $fe_htmldata = file ($fe_htmlfile); $fe_start = $fe_end = 0; for ($idx=0; $idx $value) { if ((is_array ($fe_exclude) && in_array ($key, $fe_exclude)) || $key == $fe_data["SUBMIT"]) continue; $fe_htmlblock = str_replace("{".$key."}", nl2br(htmlentities($value)), $fe_htmlblock); } $fe_header["Mime-Version"] = "1.0"; $fe_header["Content-Type"] = "multipart/related; boundary=\"".substr($fe_htmldata[1],2,-1)."\""; $fe_mess = implode ("", array_slice($fe_htmldata, 0, $fe_start)).chunk_split (base64_encode ($fe_htmlblock)).implode ("", array_slice($fe_htmldata, $fe_end+1)); } } unset ($fe_htmlfile, $fe_htmldata, $fe_start, $fe_end, $fe_htmlblock); } $fe_head = ""; foreach ($fe_header as $key => $value) $fe_head .= "\n$key: $value"; $fe_head = substr ($fe_head, 1); if (mail (trim($fe_to), $fe_subject, $fe_mess, $fe_head)) echo form_parse ($fe_post, $fe_data["SUCCESS"], $fe_data["SUBMIT"]); else echo form_parse ($fe_post, $fe_data["ERROR"], $fe_data["SUBMIT"]); unset ($fe_exclude); unset ($fe_head); unset ($fe_mess); unset ($fe_to); unset ($fe_from); } else echo form_parse ($fe_post, $fe_data["ERROR"], $fe_data["SUBMIT"]); } ?>