[ Index ] |
PHP Cross Reference of phpwcms V1.4.3 _r380 (23.11.09) |
[Summary view] [Print] [Text view]
1 <?php 2 /************************************************************************************* 3 Copyright notice 4 5 (c) 2002-2009 Oliver Georgi (oliver@phpwcms.de) // All rights reserved. 6 7 This script is part of PHPWCMS. The PHPWCMS web content management system is 8 free software; you can redistribute it and/or modify it under the terms of 9 the GNU General Public License as published by the Free Software Foundation; 10 either version 2 of the License, or (at your option) any later version. 11 12 The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html 13 A copy is found in the textfile GPL.txt and important notices to the license 14 from the author is found in LICENSE.txt distributed with these scripts. 15 16 This script is distributed in the hope that it will be useful, but WITHOUT ANY 17 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 18 PARTICULAR PURPOSE. See the GNU General Public License for more details. 19 20 This copyright notice MUST APPEAR in all copies of the script! 21 *************************************************************************************/ 22 // based on FormMail v1 23 // (c) 2003 webverbund.de Oliver Georgi (info@webverbund.de) 24 25 // Only internal form sender allowed 26 $phpwcms = array(); 27 require_once ('../../config/phpwcms/conf.inc.php'); 28 29 $url = $phpwcms["site"]; 30 $url = str_replace('http://', '', $url); 31 $url = str_replace('https://', '', $url); 32 $url = preg_replace('/\/$/', '', $url); 33 $ref = $_SERVER['HTTP_REFERER']; 34 $ref = str_replace('http://', '', $ref); 35 $ref = str_replace('https://', '', $ref); 36 if( strpos($ref, $url) === false) { 37 headerRedirect($phpwcms["site"].$phpwcms["root"]); 38 } 39 40 if(is_array($_GET)) { 41 $_GET = array(''); 42 } 43 44 require_once ('../inc_lib/default.inc.php'); 45 require_once (PHPWCMS_ROOT.'/include/inc_lib/dbcon.inc.php'); 46 47 require_once (PHPWCMS_ROOT.'/include/inc_lib/general.inc.php'); 48 require_once (PHPWCMS_ROOT.'/include/inc_lib/backend.functions.inc.php'); 49 include_once (PHPWCMS_ROOT.'/include/inc_lang/formmailer/lang.formmailer.inc.php'); 50 require_once (PHPWCMS_ROOT.'/include/inc_ext/phpmailer/class.phpmailer.php'); 51 52 53 require_once (PHPWCMS_ROOT.'/include/inc_module/mod_bad-behavior/bad-behavior-phpwcms.php'); 54 55 56 if(!checkFormTrackingValue()) { 57 58 echo '<html><head><title>phpwcms Formmailer</title></head>'; 59 echo '<body><pre>'; 60 echo 'You are not allowed to send form!'.LF; 61 echo 'Your IP: '.getRemoteIP().LF; 62 echo 'HTTP-REFERER: '.(empty($ref) ? 'unknown' : $ref); 63 echo '</pre></body></html>'; 64 exit(); 65 66 } 67 68 69 //check which language to use 70 $lang = "EN"; 71 if(isset($_POST["language"]) && strlen($_POST['language']) < 3 ) { 72 $lang = trim($_POST["language"]); 73 unset($_POST["language"]); 74 $translate[$lang] = array_merge($translate['EN'], $translate[$lang]); 75 } 76 if(!isset($translate[$lang])) $lang = "EN"; 77 78 //charset 79 if(isset($_POST["charset"])) { 80 $charset = trim($_POST["charset"]); 81 $charset = urldecode($charset); 82 $charset = str_replace('..', '', $charset); 83 $charset = str_replace('/', '', $charset); 84 $charset = str_replace('/', '', $charset); 85 unset($_POST["charset"]); 86 } 87 if(empty($charset)) $charset = 'utf-8'; 88 $content_type = 'Content-Type: text/plain; charset='.$charset."\n"; 89 90 //getting the required fields list 91 if(isset($_POST["required"])) { 92 $req_key = explode(",", trim($_POST["required"])); 93 if(count($req_key)) { 94 $err_num=0; 95 foreach($req_key as $value) { 96 $required_val[$value] = 1; 97 if(!isset($_POST[$value])) { 98 $form_error[400+$err_num] = str_replace("###value###", strtoupper($value), $translate[$lang]["error400"]); 99 $err_num+=10; 100 } 101 } 102 } 103 unset($_POST["required"]); 104 } 105 106 if(isset($_POST["Captcha_Validation"])) { 107 include_once (PHPWCMS_ROOT.'/include/inc_ext/SOLMETRA_FormValidator/SPAF_FormValidator.class.php'); 108 $spaf_obj = new SPAF_FormValidator(); 109 if($spaf_obj->validRequest($_POST["Captcha_Validation"])) { 110 $spaf_obj->destroy(); 111 unset($_POST["Captcha_Validation"]); 112 } else { 113 $form_error[350] = $translate[$lang]["error350"]; 114 } 115 } 116 //getting the label fields list 117 if(isset($_POST["label"])) { 118 $label = explode(',', trim($_POST["label"])); 119 if($label) { 120 foreach($label as $value) { 121 list($field_name, $field_label) = explode('|', $value); 122 $form_label[$field_name] = $field_label; 123 } 124 } 125 unset($_POST["label"]); 126 } 127 128 //checking for base values 129 //recipient, recipient name: 130 if(isset($_POST["recipient"])) { 131 $recipient = cleanUpFormMailerPostValue($_POST["recipient"]); 132 unset($_POST["recipient"]); 133 } 134 //check if recipient's email address is defined in conf.inc.php 135 if( isset($phpwcms["formmailer_set"]) 136 && !empty($phpwcms["formmailer_set"]['global_recipient_email']) 137 && $phpwcms["formmailer_set"]['global_recipient_email'] != 'form@localhost' 138 && is_valid_email($phpwcms["formmailer_set"]['global_recipient_email'])) { 139 $recipient = $phpwcms["formmailer_set"]['global_recipient_email']; 140 } 141 142 143 if(MailVal($recipient,2)) { //if recipient mail address is invalid 144 $form_error[100] = $translate[$lang]["error100"]; 145 } 146 if(isset($_POST["recipient_name"])) { 147 $recipient_name = cleanUpFormMailerPostValue($_POST["recipient_name"]); 148 unset($_POST["recipient_name"]); 149 } 150 //subject: 151 if(isset($_POST["subject"])) { 152 $subject = cleanUpFormMailerPostValue($_POST["subject"]); 153 $subject_encoded = encode($subject, $charset); 154 unset($_POST["subject"]); 155 } 156 if(empty($subject)) { //if recipient mail address is invalid 157 $form_error[200] = $translate[$lang]["error200"]; 158 } 159 //send copy to form sender 160 if(isset($_POST["send_copy"])) { 161 if(!empty($phpwcms["formmailer_set"]['allow_send_copy']) && intval($_POST["send_copy"])) { 162 $send_copy_to = cleanUpFormMailerPostValue($_POST["email"]); 163 if(MailVal($send_copy_to, 2)) { 164 $form_error[300] = $translate[$lang]["error300"]; 165 unset($send_copy_to); 166 } 167 } 168 unset($_POST["send_copy"]); 169 } 170 //get values for redirecting 171 if(isset($_POST["redirect"])) { 172 $redirect = trim($_POST["redirect"]); 173 unset($_POST["redirect"]); 174 } 175 if(isset($_POST["redirect_template"])) { 176 $redirect_template = trim($_POST["redirect_template"]); 177 unset($_POST["redirect_template"]); 178 } 179 if(isset($_POST["redirect_error"])) { 180 $redirect_error = trim($_POST["redirect_error"]); 181 unset($_POST["redirect_error"]); 182 } 183 if(isset($_POST["redirect_error_template"])) { 184 $redirect_error_template = trim($_POST["redirect_error_template"]); 185 unset($_POST["redirect_error_template"]); 186 } 187 188 if(isset($_POST["submit"])) unset($_POST["submit"]); 189 if(isset($_POST["type"])) unset($_POST["type"]); 190 191 //checking values and setting labels 192 if(count($_POST)) { 193 $err_num = 0; 194 foreach($_POST as $key => $value) { 195 196 //Check for required fields 197 if(!empty($required_val[$key]) && isEmpty($value) && $key != 'Captcha_Validation') { 198 if(isset($form_label[$key])) { 199 $form_error[500+$err_num] = str_replace("###value###", $form_label[$key], $translate[$lang]["error400"]); 200 } else { 201 $form_error[500+$err_num] = str_replace("###value###", strtoupper($key), $translate[$lang]["error400"]); 202 } 203 $err_num+=10; 204 } 205 206 if(is_array($value)) { //if field value is an array then split form name 207 $x = 1; 208 foreach($value as $field_value) { 209 $form[$key."[".$x."]"] = trim($field_value); 210 $x++; 211 } 212 } else { 213 $form[$key] = trim($value); 214 } 215 } 216 } 217 218 if(isset($form_error)) { 219 if(isset($redirect_error)) { 220 headerRedirect($redirect_error); 221 } else { 222 //if error show error template 223 $table = ""; 224 foreach($form_error as $key => $value) { 225 $table .= "<tr bgcolor=\"#F4F4F4\">"; 226 $table .= "<td class=\"error\">[".$key."]</td>"; 227 $table .= "<td class=\"error\">".html_specialchars($value)."</td>"; 228 $table .= "</tr>\n"; 229 } 230 231 $error_template = read_textfile(PHPWCMS_ROOT.'/include/inc_lang/formmailer/'.$lang.'_formmailer.error.html'); 232 $error_template = str_replace("<!-- RESULT //-->", $table, $error_template); 233 echo $error_template; 234 235 } 236 237 } else { 238 $translate[$lang]["bodyLine1"] = str_replace("###date###", date($translate[$lang]["dateFormat"]), $translate[$lang]["bodyLine1"]); 239 $translate[$lang]["bodyLine1"] = str_replace("###time###", date($translate[$lang]["timeFormat"]), $translate[$lang]["bodyLine1"]); 240 $body = $translate[$lang]["bodyLine1"]."\n"; 241 $body.= $translate[$lang]["bodyLine2"]."\n"; 242 $body.= $_SERVER['HTTP_REFERER']." \n"; 243 $body.= "IP: ".getRemoteIP()." \n\n"; 244 $body.= "====================================================================\n\n"; 245 $body.= $translate[$lang]["bodyRecipient"]; 246 if($recipient_name) { 247 $body.= $recipient_name." (".$recipient.")\n\n"; 248 } else { 249 $body.= $recipient."\n\n"; 250 } 251 $body.= "====================================================================\n\n"; 252 $body.= $subject."\n"; 253 $body.= "--------------------------------------------------------------------\n"; 254 255 $l=0; 256 if(is_array($form) && count($form)) { 257 foreach($form as $key => $value) { 258 $x = strlen($key); 259 if($x > $l) $l = $x; 260 } 261 foreach($form as $key => $value) { 262 $body.= str_pad($key, $l, ".").": ".$value."\n"; 263 } 264 } else { 265 $body .= LF.LF.LF; 266 $form = array(); 267 } 268 269 $body.= "\n====================================================================\n"; 270 $body.= "phpwcms formmailer | Copyright (C) 2003 \n"; 271 272 // phpMailer Class 273 $mail = new PHPMailer(); 274 $mail->Mailer = $phpwcms['SMTP_MAILER']; 275 $mail->Host = $phpwcms['SMTP_HOST']; 276 $mail->Port = $phpwcms['SMTP_PORT']; 277 if($phpwcms['SMTP_AUTH']) { 278 $mail->SMTPAuth = 1; 279 $mail->Username = $phpwcms['SMTP_USER']; 280 $mail->Password = $phpwcms['SMTP_PASS']; 281 } 282 $mail->SMTPKeepAlive = true; 283 $mail->CharSet = $phpwcms["charset"]; 284 $mail->IsHTML(0); 285 $mail->Subject = $subject; 286 $mail->Body = $body; 287 if(!$mail->SetLanguage($phpwcms['default_lang'], '')) $mail->SetLanguage('en', ''); 288 $false = ''; 289 290 291 if(isset($send_copy_to)) { 292 //$from = "From: ".$send_copy_to."\nReply-To: ".$send_copy_to."\n"; 293 //if(!ini_get('safe_mode')) { 294 // mail($send_copy_to, $subject_encoded, $body, "From: ".$recipient."\n".$content_type, "-f".$recipient); 295 //} else { 296 //mail($send_copy_to, $subject_encoded, $body, "From: ".$recipient."\nReply-To: ".$recipient."\n".$content_type); 297 //} 298 299 $mail->From = $recipient; 300 $mail->FromName = $phpwcms['SMTP_FROM_NAME']; 301 $mail->Sender = $recipient; 302 $mail->AddAddress($send_copy_to); 303 304 if(!$mail->Send()) { 305 $false .= '(1) '.html_specialchars($mail->ErrorInfo).'<br>'; 306 } 307 308 $mail->From = $send_copy_to; 309 $mail->FromName = ''; 310 $mail->Sender = $send_copy_to; 311 312 313 } else { 314 315 $mail->From = $recipient; 316 $mail->FromName = $phpwcms['SMTP_FROM_NAME']; 317 $mail->Sender = $recipient; 318 319 } 320 321 $mail->ClearAddresses(); 322 $mail->AddAddress($recipient); 323 324 if(!$mail->Send()) { 325 $false .= '(2) '.html_specialchars($mail->ErrorInfo).'<br>'; 326 } 327 328 $mail->SmtpClose(); 329 330 if(isset($redirect) && !$false) { 331 headerRedirect($redirect); 332 } else { 333 334 //Success show form success template 335 $table = ""; 336 if($false) { 337 $table .= '<tr bgcolor="#F4F4F4">'; 338 $table .= "<td>Mailer Error:</td>"; 339 $table .= "<td>".$false."</td>"; 340 $table .= "</tr>\n"; 341 } 342 343 foreach($form as $key => $value) { 344 $table .= "<tr bgcolor=\"#F4F4F4\">"; 345 $table .= "<td>".html_specialchars($key)."</td>"; 346 $table .= "<td>".html_specialchars($value)."</td>"; 347 $table .= "</tr>\n"; 348 } 349 350 $success_template = read_textfile(PHPWCMS_ROOT.'/include/inc_lang/formmailer/'.$lang.'_formmailer.success.html'); 351 $success_template = str_replace("<!-- RESULT //-->", $table, $success_template); 352 echo $success_template; 353 354 } 355 } 356 357 358 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Dec 30 05:55:15 2009 | Cross-referenced by PHPXref 0.7 |