[ Index ] |
|
Code source de Zen Cart E-Commerce Shopping Cart 1.3.7.1 |
1 <?php 2 /** 3 * functions_email.php 4 * Processes all email activities from Zen Cart 5 * Hooks into phpMailer class for actual email encoding and sending 6 * 7 * @package functions 8 * @copyright Copyright 2003-2006 Zen Cart Development Team 9 * @copyright Portions Copyright 2003 osCommerce 10 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 11 * @version $Id: functions_email.php 6540 2007-07-01 19:41:08Z drbyte $ 12 */ 13 14 /** 15 * Set email system debugging off or on 16 * 0=off 17 * 1=show SMTP status errors 18 * 2=show SMTP server responses 19 * 4=show SMTP readlines if applicable 20 * 5=maximum information 21 * 'preview' to show HTML-emails on-screen while sending 22 */ 23 define('EMAIL_SYSTEM_DEBUG','0'); 24 25 /** 26 * Send email (text/html) using MIME. This is the central mail function. 27 * The SMTP Server should be configured correctly in php.ini 28 * 29 * @param string $to_name The name of the recipient, e.g. "Jim Johanssen" 30 * @param string $to_email_address The eMail address of the recipient, e.g. john.smith@hzq.com 31 * (used as $to_email_address after validation) 32 * @param string $email_subject The subject of the eMail 33 * @param string $email_text The text of the eMail, may contain HTML entities 34 * @param string $from_email_name The name of the sender, e.g. Shop Administration 35 * @param string $from_email_adrdess The eMail address of the sender, e.g. info@myzenshop.com 36 * @param array $block Array containing values to be inserted into HTML-based email template 37 * @param string $module The module name of the routine calling zen_mail. Used for html template selection and email archiving. 38 * This is passed to the archive function denoting what module initiated the sending of the email 39 * @param array $attachments_list Array of attachment names/mime-types to be included (this portion still in testing, and not fully reliable) 40 **/ 41 function zen_mail($to_name, $to_address, $email_subject, $email_text, $from_email_name, $from_email_address, $block=array(), $module='default', $attachments_list='' ) { 42 global $db, $messageStack, $zco_notifier; 43 if (!defined('DEVELOPER_OVERRIDE_EMAIL_STATUS') || (defined('DEVELOPER_OVERRIDE_EMAIL_STATUS') && DEVELOPER_OVERRIDE_EMAIL_STATUS == 'site')) 44 if (SEND_EMAILS != 'true') return false; // if sending email is disabled in Admin, just exit 45 46 if (defined('DEVELOPER_OVERRIDE_EMAIL_ADDRESS') && DEVELOPER_OVERRIDE_EMAIL_ADDRESS != '') $to_address = DEVELOPER_OVERRIDE_EMAIL_ADDRESS; 47 48 // ignore sending emails for any of the following pages 49 // (The EMAIL_MODULES_TO_SKIP constant can be defined in a new file in the "extra_configures" folder) 50 if (defined('EMAIL_MODULES_TO_SKIP') && in_array($module,explode(",",constant('EMAIL_MODULES_TO_SKIP')))) return false; 51 52 // check for injection attempts. If new-line characters found in header fields, simply fail to send the message 53 foreach(array($from_email_address, $to_address, $from_email_name, $to_name, $email_subject) as $key=>$value) { 54 if (eregi("\r",$value) || eregi("\n",$value)) return false; 55 } 56 57 // if no text or html-msg supplied, exit 58 if (!zen_not_null($email_text) && !zen_not_null($block['EMAIL_MESSAGE_HTML'])) return false; 59 60 // Parse "from" addresses for "name" <email@address.com> structure, and supply name/address info from it. 61 if (eregi(" *([^<]*) *<([^>]*)> *",$from_email_address,$regs)) { 62 $from_email_name = trim($regs[1]); 63 $from_email_address = $regs[2]; 64 } 65 // if email name is same as email address, use the Store Name as the senders 'Name' 66 if ($from_email_name == $from_email_address) $from_email_name = STORE_NAME; 67 68 // loop thru multiple email recipients if more than one listed --- (esp for the admin's "Extra" emails)... 69 foreach(explode(',',$to_address) as $key=>$value) { 70 if (eregi(" *([^<]*) *<([^>]*)> *",$value,$regs)) { 71 $to_name = str_replace('"', '', trim($regs[1])); 72 $to_email_address = $regs[2]; 73 } elseif (eregi(" *([^ ]*) *",$value,$regs)) { 74 $to_email_address = trim($regs[1]); 75 } 76 if (!isset($to_email_address)) $to_email_address=$to_address; //if not more than one, just use the main one. 77 78 //define some additional html message blocks available to templates, then build the html portion. 79 if ($block['EMAIL_TO_NAME']=='') $block['EMAIL_TO_NAME'] = $to_name; 80 if ($block['EMAIL_TO_ADDRESS']=='') $block['EMAIL_TO_ADDRESS'] = $to_email_address; 81 if ($block['EMAIL_SUBJECT']=='') $block['EMAIL_SUBJECT'] = $email_subject; 82 if ($block['EMAIL_FROM_NAME']=='') $block['EMAIL_FROM_NAME'] = $from_email_name; 83 if ($block['EMAIL_FROM_ADDRESS']=='') $block['EMAIL_FROM_ADDRESS'] = $from_email_address; 84 $email_html = zen_build_html_email_from_template($module, $block); 85 86 // if ($attachments_list == '') $attachments_list= array(); 87 88 // bof: body of the email clean-up 89 // clean up & and && from email text 90 while (strstr($email_text, '&&')) $email_text = str_replace('&&', '&', $email_text); 91 while (strstr($email_text, '&')) $email_text = str_replace('&', '&', $email_text); 92 while (strstr($email_text, '&&')) $email_text = str_replace('&&', '&', $email_text); 93 94 // clean up currencies for text emails 95 $zen_fix_currencies = split("[:,]" , CURRENCIES_TRANSLATIONS); 96 $size = sizeof($zen_fix_currencies); 97 for ($i=0, $n=$size; $i<$n; $i+=2) { 98 $zen_fix_current = $zen_fix_currencies[$i]; 99 $zen_fix_replace = $zen_fix_currencies[$i+1]; 100 if (strlen($zen_fix_current)>0) { 101 while (strpos($email_text, $zen_fix_current)) $email_text = str_replace($zen_fix_current, $zen_fix_replace, $email_text); 102 } 103 } 104 105 // fix double quotes 106 while (strstr($email_text, '"')) $email_text = str_replace('"', '"', $email_text); 107 108 // fix slashes 109 $email_text = stripslashes($email_text); 110 $email_html = stripslashes($email_html); 111 112 // eof: body of the email clean-up 113 114 //determine customer's email preference type: HTML or TEXT-ONLY (HTML assumed if not specified) 115 $customers_email_format_read = $db->Execute("select customers_email_format from " . TABLE_CUSTOMERS . " where customers_email_address= '" . $to_email_address . "'"); 116 $customers_email_format = $customers_email_format_read->fields['customers_email_format']; 117 if ($customers_email_format=='NONE' || $customers_email_format=='OUT') return; //if requested no mail, then don't send. 118 if ($customers_email_format =='HTML') $customers_email_format='HTML'; // if they opted-in to HTML messages, then send HTML format 119 120 //determine what format to send messages in if this is an "extra"/admin-copy email: 121 if (ADMIN_EXTRA_EMAIL_FORMAT == 'TEXT' && substr($module,-6)=='_extra') { 122 $email_html=''; // just blank out the html portion if admin has selected text-only 123 } 124 125 //notifier intercept option 126 $zco_notifier->notify('NOTIFY_EMAIL_AFTER_EMAIL_FORMAT_DETERMINED'); 127 128 // Build the email based on whether customer has selected HTML or TEXT, and whether we have supplied HTML or TEXT-only components 129 if (!zen_not_null($email_text)) { 130 $text = str_replace('<br[[:space:]]*/?[[:space:]]*>', "\n", $block['EMAIL_MESSAGE_HTML']); 131 $text = str_replace('</p>', "</p>\n", $text); 132 $text = htmlspecialchars(stripslashes(strip_tags($text))); 133 } else { 134 $text = strip_tags($email_text); 135 } 136 137 // now lets build the mail object with the phpmailer class 138 $mail = & new PHPMailer(); 139 $lang_code = strtolower(($_SESSION['languages_code'] == '' ? 'en' : $_SESSION['languages_code'] )); 140 $mail->SetLanguage($lang_code, DIR_FS_CATALOG . DIR_WS_CLASSES . 'support/'); 141 $mail->CharSet = (defined('CHARSET')) ? CHARSET : "iso-8859-1"; 142 $mail->Encoding = (defined('EMAIL_ENCODING_METHOD')) ? EMAIL_ENCODING_METHOD : "7bit"; 143 if ((int)EMAIL_SYSTEM_DEBUG > 0 ) $mail->SMTPDebug = (int)EMAIL_SYSTEM_DEBUG; 144 145 switch (EMAIL_TRANSPORT) { 146 case 'smtp': 147 $mail->IsSMTP(); 148 $mail->Host = EMAIL_SMTPAUTH_MAIL_SERVER; 149 if (EMAIL_SMTPAUTH_MAIL_SERVER_PORT != '25' && EMAIL_SMTPAUTH_MAIL_SERVER_PORT != '') $mail->Port = EMAIL_SMTPAUTH_MAIL_SERVER_PORT; 150 break; 151 case 'smtpauth': 152 $mail->IsSMTP(); 153 $mail->SMTPAuth = true; 154 $mail->Username = (zen_not_null(EMAIL_SMTPAUTH_MAILBOX)) ? EMAIL_SMTPAUTH_MAILBOX : EMAIL_FROM; 155 $mail->Password = EMAIL_SMTPAUTH_PASSWORD; 156 $mail->Host = EMAIL_SMTPAUTH_MAIL_SERVER; 157 if (EMAIL_SMTPAUTH_MAIL_SERVER_PORT != '25' && EMAIL_SMTPAUTH_MAIL_SERVER_PORT != '') $mail->Port = EMAIL_SMTPAUTH_MAIL_SERVER_PORT; 158 break; 159 case 'PHP': 160 $mail->IsMail(); 161 break; 162 case 'Qmail': 163 $mail->IsQmail(); 164 break; 165 case 'sendmail': 166 case 'sendmail-f': 167 default: 168 $mail->IsSendmail(); 169 if (defined('EMAIL_SENDMAIL_PATH')) $mail->Sendmail = EMAIL_SENDMAIL_PATH; 170 break; 171 } 172 173 $mail->Subject = $email_subject; 174 $mail->From = $from_email_address; 175 $mail->FromName = $from_email_name; 176 $mail->AddAddress($to_email_address, $to_name); 177 // $mail->AddAddress($to_email_address); // (alternate format if no name, since name is optional) 178 179 // set proper line-endings based on switch ... important for windows vs linux hosts: 180 $mail->LE = (EMAIL_LINEFEED == 'CRLF') ? "\r\n" : "\n"; 181 182 $mail->WordWrap = 76; // set word wrap to 76 characters 183 184 // set the reply-to address. If none set yet, then use Store's default email name/address. 185 // If sending from contact-us or tell-a-friend page, use the supplied info 186 $email_reply_to_address = ($email_reply_to_address) ? $email_reply_to_address : (in_array($module, array('contact_us', 'tell_a_friend')) ? $from_email_address : EMAIL_FROM); 187 $email_reply_to_name = ($email_reply_to_name) ? $email_reply_to_name : (in_array($module, array('contact_us', 'tell_a_friend')) ? $from_email_name : STORE_NAME); 188 $mail->AddReplyTo($email_reply_to_address, $email_reply_to_name); 189 190 // if mailserver requires that all outgoing mail must go "from" an email address matching domain on server, set it to store address 191 if (EMAIL_SEND_MUST_BE_STORE=='Yes') $mail->From = EMAIL_FROM; 192 193 if (EMAIL_TRANSPORT=='sendmail-f' || EMAIL_SEND_MUST_BE_STORE=='Yes') { 194 $mail->Sender = EMAIL_FROM; 195 } 196 197 // process attachments 198 $zco_notifier->notify('NOTIFY_EMAIL_BEFORE_PROCESS_ATTACHMENTS'); 199 // Note: $attachments_list array requires that the 'file' portion contains the full path to the file to be attached 200 if (EMAIL_ATTACHMENTS_ENABLED && zen_not_null($attachments_list) ) { 201 // if ($attachments_list == '') $attachments_list = array(); 202 // while ( list($key, $value) = each($attachments_list)) { 203 // $mail->AddAttachment($value['file']); // add attachments 204 205 $mail->AddAttachment($attachments_list['file']); // add attachments 206 // $mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // optional format if specifying filename 207 208 // } //endwhile attach_list 209 } //endif attachments 210 $zco_notifier->notify('NOTIFY_EMAIL_AFTER_PROCESS_ATTACHMENTS'); 211 212 if (EMAIL_USE_HTML == 'true' && trim($email_html) != '' && 213 ($customers_email_format == 'HTML' || (ADMIN_EXTRA_EMAIL_FORMAT != 'TEXT' && substr($module,-6)=='_extra'))) { 214 $mail->IsHTML(true); // set email format to HTML 215 $mail->Body = $email_html; // HTML-content of message 216 $mail->AltBody = $text; // text-only content of message 217 } else { // use only text portion if not HTML-formatted 218 $mail->Body = $text; // text-only content of message 219 } 220 221 /** 222 * Send the email. If an error occurs, trap it and display it in the messageStack 223 */ 224 $zco_notifier->notify('NOTIFY_EMAIL_READY_TO_SEND'); 225 if (!$mail->Send()) { 226 $messageStack->add('header',sprintf(EMAIL_SEND_FAILED . ' '. $mail->ErrorInfo, $to_name, $to_email_address, $email_subject),'error'); 227 $ErrorInfo .= $mail->ErrorInfo . '<br />'; 228 } 229 $zco_notifier->notify('NOTIFY_EMAIL_AFTER_SEND'); 230 231 // Archive this message to storage log 232 // don't archive pwd-resets and CC numbers 233 if (EMAIL_ARCHIVE == 'true' && $module != 'password_forgotten_admin' && $module != 'cc_middle_digs' && $module != 'no_archive') { 234 zen_mail_archive_write($to_name, $to_email_address, $from_email_name, $from_email_address, $email_subject, $email_html, $text, $module ); 235 } // endif archiving 236 } // end foreach loop thru possible multiple email addresses 237 $zco_notifier->notify('NOTIFY_EMAIL_AFTER_SEND_ALL_SPECIFIED_ADDRESSES'); 238 239 if (EMAIL_FRIENDLY_ERRORS=='false' && $ErrorInfo != '') die('<br /><br />Email Error: ' . $ErrorInfo); 240 241 return $ErrorInfo; 242 } // end function 243 244 /** 245 * zen_mail_archive_write() 246 * 247 * this function stores sent emails into a table in the database as a log record of email activity. This table CAN get VERY big! 248 * To disable this function, set the "Email Archives" switch to 'false' in ADMIN! 249 * 250 * See zen_mail() function description for more details on the meaning of these parameters 251 * @param string $to_name 252 * @param string $to_email_address 253 * @param string $from_email_name 254 * @param string $from_email_address 255 * @param string $email_subject 256 * @param string $email_html 257 * @param array $email_text 258 * @param string $module 259 **/ 260 function zen_mail_archive_write($to_name, $to_email_address, $from_email_name, $from_email_address, $email_subject, $email_html, $email_text, $module) { 261 global $db; 262 $to_name = zen_db_prepare_input($to_name); 263 $to_email_address = zen_db_prepare_input($to_email_address); 264 $from_email_name = zen_db_prepare_input($from_email_name); 265 $from_email_address = zen_db_prepare_input($from_email_address); 266 $email_subject = zen_db_prepare_input($email_subject); 267 $email_html = (EMAIL_USE_HTML=='true') ? zen_db_prepare_input($email_html) : zen_db_prepare_input('HTML disabled in admin'); 268 $email_text = zen_db_prepare_input($email_text); 269 $module = zen_db_prepare_input($module); 270 271 $db->Execute("insert into " . TABLE_EMAIL_ARCHIVE . " 272 (email_to_name, email_to_address, email_from_name, email_from_address, email_subject, email_html, email_text, date_sent, module) 273 values ('" . zen_db_input($to_name) . "', 274 '" . zen_db_input($to_email_address) . "', 275 '" . zen_db_input($from_email_name) . "', 276 '" . zen_db_input($from_email_address) . "', 277 '" . zen_db_input($email_subject) . "', 278 '" . zen_db_input($email_html) . "', 279 '" . zen_db_input($email_text) . "', 280 now() , 281 '" . zen_db_input($module) . "')"); 282 return $db; 283 } 284 285 //DEFINE EMAIL-ARCHIVABLE-MODULES LIST // this array will likely be used by the email archive log VIEWER module in future 286 $emodules_array = array(); 287 $emodules_array[] = array('id' => 'newsletters', 'text' => 'Newsletters'); 288 $emodules_array[] = array('id' => 'product_notification', 'text' => 'Product Notifications'); 289 $emodules_array[] = array('id' => 'direct_email', 'text' => 'One-Time Email'); 290 $emodules_array[] = array('id' => 'contact_us', 'text' => 'Contact Us'); 291 $emodules_array[] = array('id' => 'coupon', 'text' => 'Send Coupon'); 292 $emodules_array[] = array('id' => 'coupon_extra', 'text' => 'Send Coupon'); 293 $emodules_array[] = array('id' => 'gv_queue', 'text' => 'Send-GV-Queue'); 294 $emodules_array[] = array('id' => 'gv_mail', 'text' => 'Send-GV'); 295 $emodules_array[] = array('id' => 'gv_mail_extra', 'text' => 'Send-GV-Extra'); 296 $emodules_array[] = array('id' => 'welcome', 'text' => 'New Customer Welcome'); 297 $emodules_array[] = array('id' => 'welcome_extra', 'text' => 'New Customer Welcome-Extra'); 298 $emodules_array[] = array('id' => 'password_forgotten', 'text' => 'Password Forgotten'); 299 $emodules_array[] = array('id' => 'password_forgotten_admin', 'text' => 'Password Forgotten'); 300 $emodules_array[] = array('id' => 'checkout', 'text' => 'Checkout'); 301 $emodules_array[] = array('id' => 'checkout_extra', 'text' => 'Checkout-Extra'); 302 $emodules_array[] = array('id' => 'order_status', 'text' => 'Order Status'); 303 $emodules_array[] = array('id' => 'order_status_extra', 'text' => 'Order Status-Extra'); 304 $emodules_array[] = array('id' => 'low_stock', 'text' => 'Low Stock Notices'); 305 $emodules_array[] = array('id' => 'cc_middle_digs', 'text' => 'CC - Middle-Digits'); 306 $emodules_array[] = array('id' => 'tell_a_friend', 'text' => 'Tell-A-Friend'); 307 $emodules_array[] = array('id' => 'tell_a_friend_extra', 'text' => 'Tell-A-Friend-Extra'); 308 $emodules_array[] = array('id' => 'purchase_order', 'text' => 'Purchase Order'); 309 $emodules_array[] = array('id' => 'payment_modules', 'text' => 'Payment Modules'); 310 $emodules_array[] = array('id' => 'payment_modules_extra', 'text' => 'Payment Modules-Extra'); 311 ///////////////////////////////////////////////////////////////////////////////////////// 312 ////////END SECTION FOR EMAIL FUNCTIONS////////////////////////////////////////////////// 313 ///////////////////////////////////////////////////////////////////////////////////////// 314 315 316 /** 317 * select email template based on 'module' (supplied as param to function) 318 * selectively go thru each template tag and substitute appropriate text 319 * finally, build full html content as "return" output from class 320 **/ 321 function zen_build_html_email_from_template($module='default',$block='') { 322 global $messageStack, $current_page_base; 323 if ($block == '' && !is_array($block)) $block = array(); 324 325 // Identify and Read the template file for the type of message being sent 326 $template_filename_base = DIR_FS_EMAIL_TEMPLATES . "email_template_"; 327 $template_filename = DIR_FS_EMAIL_TEMPLATES . "email_template_" . $current_page_base . ".html"; 328 329 if (!file_exists($template_filename)) { 330 if (file_exists($template_filename_base . str_replace(array('_extra','_admin'),'',$module) . '.html')) { 331 $template_filename = $template_filename_base . str_replace(array('_extra','_admin'),'',$module) . '.html'; 332 } elseif (file_exists($template_filename_base . 'default' . '.html')) { 333 $template_filename = $template_filename_base . 'default' . '.html'; 334 } else { 335 $messageStack->add('header','ERROR: The email template file for ('.$template_filename_base.') or ('.$template_filename.') cannot be found.','caution'); 336 return ''; // couldn't find template file, so return an empty string for html message. 337 } 338 } 339 340 if (! $fh = fopen($template_filename, 'rb')) { // note: the 'b' is for compatibility with Windows systems 341 $messageStack->add('header','ERROR: The email template file ('.$template_filename_base.') or ('.$template_filename.') cannot be opened','caution'); 342 } 343 344 $file_holder = fread($fh, filesize($template_filename)); 345 fclose($fh); 346 347 //strip linebreaks and tabs out of the template 348 // $file_holder = str_replace(array("\r\n", "\n", "\r", "\t"), '', $file_holder); 349 $file_holder = str_replace(array("\t"), ' ', $file_holder); 350 351 352 if (!defined('HTTP_CATALOG_SERVER')) define('HTTP_CATALOG_SERVER', HTTP_SERVER); 353 //check for some specifics that need to be included with all messages 354 if ($block['EMAIL_STORE_NAME']=='') $block['EMAIL_STORE_NAME'] = STORE_NAME; 355 if ($block['EMAIL_STORE_URL']=='') $block['EMAIL_STORE_URL'] = '<a href="'.HTTP_CATALOG_SERVER . DIR_WS_CATALOG.'">'.STORE_NAME.'</a>'; 356 if ($block['EMAIL_STORE_OWNER']=='') $block['EMAIL_STORE_OWNER'] = STORE_OWNER; 357 if ($block['EMAIL_FOOTER_COPYRIGHT']=='') $block['EMAIL_FOOTER_COPYRIGHT'] = EMAIL_FOOTER_COPYRIGHT; 358 if ($block['EMAIL_DISCLAIMER']=='') $block['EMAIL_DISCLAIMER'] = sprintf(EMAIL_DISCLAIMER, '<a href="mailto:' . STORE_OWNER_EMAIL_ADDRESS . '">'. STORE_OWNER_EMAIL_ADDRESS .' </a>'); 359 if ($block['EMAIL_SPAM_DISCLAIMER']=='') $block['EMAIL_SPAM_DISCLAIMER'] = EMAIL_SPAM_DISCLAIMER; 360 if ($block['BASE_HREF']=='') $block['BASE_HREF'] = HTTP_SERVER . DIR_WS_CATALOG; 361 if ($block['EMAIL_DATE_SHORT']=='') $block['EMAIL_DATE_SHORT'] = zen_date_short(date("Y-m-d")); 362 if ($block['EMAIL_DATE_LONG']=='') $block['EMAIL_DATE_LONG'] = zen_date_long(date("Y-m-d")); 363 if ($block['CHARSET']=='') $block['CHARSET'] = CHARSET; 364 // if ($block['EMAIL_STYLESHEET']=='') $block['EMAIL_STYLESHEET'] = str_replace(array("\r\n", "\n", "\r"), "",@file_get_contents(DIR_FS_EMAIL_TEMPLATES.'stylesheet.css')); 365 366 if (!isset($block['EXTRA_INFO'])) $block['EXTRA_INFO'] = ''; 367 if (substr($module,-6) != '_extra' && $module != 'contact_us') $block['EXTRA_INFO'] = ''; 368 369 $block['COUPON_BLOCK'] = ''; 370 if ($block['COUPON_TEXT_VOUCHER_IS'] && $block['COUPON_TEXT_TO_REDEEM']) { 371 $block['COUPON_BLOCK'] = '<div class="coupon-block">' . $block['COUPON_TEXT_VOUCHER_IS'] . $block['COUPON_DESCRIPTION'] . '<br />' . $block['COUPON_TEXT_TO_REDEEM'] . '<span class="coupon-code">' . $block['COUPON_CODE'] . '</span></div>'; 372 } 373 374 $block['GV_BLOCK'] = ''; 375 if ($block['GV_WORTH'] && $block['GV_REDEEM'] && $block['GV_CODE_URL']) { 376 $block['GV_BLOCK'] = '<div class="gv-block">' . $block['GV_WORTH'] . '<br />' . $block['GV_REDEEM'] . $block['GV_CODE_URL'] . '<br />' . $block['GV_LINK_OTHER'] . '</div>'; 377 } 378 379 //prepare the "unsubscribe" link: 380 if (IS_ADMIN_FLAG === true) { // is this admin version, or catalog? 381 $block['UNSUBSCRIBE_LINK'] = str_replace("\n",'',TEXT_UNSUBSCRIBE) . ' <a href="' . zen_catalog_href_link(FILENAME_UNSUBSCRIBE, "addr=" . $block['EMAIL_TO_ADDRESS']) . '">' . zen_catalog_href_link(FILENAME_UNSUBSCRIBE, "addr=" . $block['EMAIL_TO_ADDRESS']) . '</a>'; 382 } else { 383 $block['UNSUBSCRIBE_LINK'] = str_replace("\n",'',TEXT_UNSUBSCRIBE) . ' <a href="' . zen_href_link(FILENAME_UNSUBSCRIBE, "addr=" . $block['EMAIL_TO_ADDRESS']) . '">' . zen_href_link(FILENAME_UNSUBSCRIBE, "addr=" . $block['EMAIL_TO_ADDRESS']) . '</a>'; 384 } 385 386 //now replace the $BLOCK_NAME items in the template file with the values passed to this function's array 387 foreach ($block as $key=>$value) { 388 $file_holder = str_replace('$' . $key, $value, $file_holder); 389 } 390 391 //DEBUG -- to display preview on-screen 392 if (EMAIL_SYSTEM_DEBUG=='preview') echo $file_holder; 393 394 return $file_holder; 395 } 396 397 398 /** 399 * Function to build array of additional email content collected and sent on admin-copies of emails: 400 * 401 */ 402 function email_collect_extra_info($from, $email_from, $login, $login_email, $login_phone='', $login_fax='') { 403 // get host_address from either session or one time for both email types to save server load 404 if (!$_SESSION['customers_host_address']) { 405 if (SESSION_IP_TO_HOST_ADDRESS == 'true') { 406 $email_host_address = gethostbyaddr($_SERVER['REMOTE_ADDR']); 407 } else { 408 $email_host_address = OFFICE_IP_TO_HOST_ADDRESS; 409 } 410 } else { 411 $email_host_address = $_SESSION['customers_host_address']; 412 } 413 414 // generate footer details for "also-send-to" emails 415 $extra_info=array(); 416 $extra_info['TEXT'] = 417 OFFICE_USE . "\t" . "\n" . 418 OFFICE_FROM . "\t" . $from . "\n" . 419 OFFICE_EMAIL. "\t" . $email_from . "\n" . 420 (trim($login) !='' ? OFFICE_LOGIN_NAME . "\t" . $login . "\n" : '') . 421 (trim($login_email) !='' ? OFFICE_LOGIN_EMAIL . "\t" . $login_email . "\n" : '') . 422 ($login_phone !='' ? OFFICE_LOGIN_PHONE . "\t" . $login_phone . "\n" : '') . 423 ($login_fax !='' ? OFFICE_LOGIN_FAX . "\t" . $login_fax . "\n" : '') . 424 OFFICE_IP_ADDRESS . "\t" . $_SESSION['customers_ip_address'] . ' - ' . $_SERVER['REMOTE_ADDR'] . "\n" . 425 OFFICE_HOST_ADDRESS . "\t" . $email_host_address . "\n" . 426 OFFICE_DATE_TIME . "\t" . date("D M j Y G:i:s T") . "\n\n"; 427 428 $extra_info['HTML'] = '<table class="extra-info">' . 429 '<tr><td class="extra-info-bold" colspan="2">' . OFFICE_USE . '</td></tr>' . 430 '<tr><td class="extra-info-bold">' . OFFICE_FROM . '</td><td>' . $from . '</td></tr>' . 431 '<tr><td class="extra-info-bold">' . OFFICE_EMAIL. '</td><td>' . $email_from . '</td></tr>' . 432 ($login !='' ? '<tr><td class="extra-info-bold">' . OFFICE_LOGIN_NAME . '</td><td>' . $login . '</td></tr>' : '') . 433 ($login_email !='' ? '<tr><td class="extra-info-bold">' . OFFICE_LOGIN_EMAIL . '</td><td>' . $login_email . '</td></tr>' : '') . 434 ($login_phone !='' ? '<tr><td class="extra-info-bold">' . OFFICE_LOGIN_PHONE . '</td><td>' . $login_phone . '</td></tr>' : '') . 435 ($login_fax !='' ? '<tr><td class="extra-info-bold">' . OFFICE_LOGIN_FAX . '</td><td>' . $login_fax . '</td></tr>' : '') . 436 '<tr><td class="extra-info-bold">' . OFFICE_IP_ADDRESS . '</td><td>' . $_SESSION['customers_ip_address'] . ' - ' . $_SERVER['REMOTE_ADDR'] . '</td></tr>' . 437 '<tr><td class="extra-info-bold">' . OFFICE_HOST_ADDRESS . '</td><td>' . $email_host_address . '</td></tr>' . 438 '<tr><td class="extra-info-bold">' . OFFICE_DATE_TIME . '</td><td>' . date('D M j Y G:i:s T') . '</td></tr>' . '</table>'; 439 return $extra_info; 440 } 441 442 443 444 445 446 /** 447 * validates an email address 448 * 449 * Sample Valid Addresses: 450 * 451 * first.last@host.com 452 * firstlast@host.to 453 * "first last"@host.com 454 * "first@last"@host.com 455 * first-last@host.com 456 * first's-address@email.host.4somewhere.com 457 * first.last@[123.123.123.123] 458 * 459 * hosts with either external IP addresses or from 2-6 characters will pass (e.g. .jp or .museum) 460 * 461 * Invalid Addresses: 462 * 463 * first last@host.com 464 * 'first@host.com 465 * @param string The email address to validate 466 * @return booloean true if valid else false 467 **/ 468 function zen_validate_email($email) { 469 $valid_address = true; 470 471 // fail if contains no @ symbol 472 if (!strstr($email,'@')) return false; 473 474 // split the email address into user and domain parts 475 // need to update to trap for addresses in the format of "first@last"@someplace.com 476 // this method will most likely break in that case 477 list( $user, $domain ) = explode( "@", $email ); 478 $valid_ip_form = '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'; 479 $valid_email_pattern = '^[a-z0-9]+[a-z0-9_\.\'\-]*@[a-z0-9]+[a-z0-9\.\-]*\.(([a-z]{2,6})|([0-9]{1,3}))$'; 480 //preg_match('/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9\._-]+)+$/', $email)) 481 //preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*?[a-z]+$/is'); 482 $space_check = '[ ]'; 483 484 // strip beginning and ending quotes, if and only if both present 485 if( (ereg('^["]', $user) && ereg('["]$', $user)) ){ 486 $user = ereg_replace ( '^["]', '', $user ); 487 $user = ereg_replace ( '["]$', '', $user ); 488 $user = ereg_replace ( $space_check, '', $user ); //spaces in quoted addresses OK per RFC (?) 489 $email = $user."@".$domain; // contine with stripped quotes for remainder 490 } 491 492 // fail if contains spaces in domain name 493 if (strstr($domain,' ')) return false; 494 495 // if email domain part is an IP address, check each part for a value under 256 496 if (ereg($valid_ip_form, $domain)) { 497 $digit = explode( ".", $domain ); 498 for($i=0; $i<4; $i++) { 499 if ($digit[$i] > 255) { 500 $valid_address = false; 501 return $valid_address; 502 exit; 503 } 504 // stop crafty people from using internal IP addresses 505 if (($digit[0] == 192) || ($digit[0] == 10)) { 506 $valid_address = false; 507 return $valid_address; 508 exit; 509 } 510 } 511 } 512 513 if (!ereg($space_check, $email)) { // trap for spaces in 514 if ( eregi($valid_email_pattern, $email)) { // validate against valid email patterns 515 $valid_address = true; 516 } else { 517 $valid_address = false; 518 return $valid_address; 519 exit; 520 } 521 } 522 return $valid_address; 523 } 524 525 526 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 16:45:43 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |