[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
Zen Cart 源代码 mail.php

Zen Cart 源代码 mail.php




下载文件

文件名: mail.php
文件类型: PHP文件
文件大小: 18.36 KiB
MD5: 9e8cf0ca72d68cf6d86d62ebeb12248b

mail.php - 关闭高亮
  1. <?php
  2. /**
  3.  * @package admin
  4.  * @copyright Copyright 2003-2012 Zen Cart Development Team
  5.  * @copyright Portions Copyright 2003 osCommerce
  6.  * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  7.  * @version GIT: $Id: Author: Ian Wilson  Tue Aug 7 15:17:58 2012 +0100 Modified in v1.5.1 $
  8.  */
  9.  
  10.   require('includes/application_top.php');
  11.  
  12.   //DEBUG:  // these defines will become configuration switches in ADMIN in a future version.
  13.   //DEBUG:  // right now, attachments aren't working right unless only sending HTML messages with NO text-only version supplied.
  14.   if (!defined('EMAIL_ATTACHMENTS_ENABLED'))        define('EMAIL_ATTACHMENTS_ENABLED',false);
  15.   if (!defined('EMAIL_ATTACHMENT_UPLOADS_ENABLED')) define('EMAIL_ATTACHMENT_UPLOADS_ENABLED',false);
  16.  
  17.  
  18.   $action = (isset($_GET['action']) ? $_GET['action'] : '');
  19.  
  20.   if ($action == 'set_editor') {
  21.     // Reset will be done by init_html_editor.php. Now we simply redirect to refresh page properly.
  22.     $action='';
  23.     zen_redirect(zen_href_link(FILENAME_MAIL));
  24.   }
  25.  
  26.   if ( ($action == 'send_email_to_user') && isset($_POST['customers_email_address']) && !isset($_POST['back_x']) ) {
  27.     $audience_select = get_audience_sql_query(zen_db_input($_POST['customers_email_address']), 'email');
  28.     $mail = $db->Execute($audience_select['query_string']);
  29.     $mail_sent_to = $audience_select['query_name'];
  30.     if ($_POST['email_to']) {
  31.       $mail_sent_to = zen_db_prepare_input($_POST['email_to']);
  32.     }
  33.  
  34.     // error message if no email address
  35.     if (empty($mail_sent_to)) {
  36.       $messageStack->add_session(ERROR_NO_CUSTOMER_SELECTED, 'error');
  37.       $_GET['action']='';
  38.       zen_redirect(zen_href_link(FILENAME_MAIL));
  39.     }
  40.  
  41.     $from = zen_db_prepare_input($_POST['from']);
  42.     $subject = zen_db_prepare_input($_POST['subject']);
  43.     $message = zen_db_prepare_input($_POST['message']);
  44.     $html_msg['EMAIL_MESSAGE_HTML'] = zen_db_prepare_input($_POST['message_html']);
  45.     $attachment_file = $_POST['attachment_file'];
  46.     $attachment_fname = basename($_POST['attachment_file']);
  47.     $attachment_filetype = $_POST['attachment_filetype'];
  48.  
  49.     // demo active test
  50.     if (zen_admin_demo()) {
  51.       $_GET['action']= '';
  52.       $messageStack->add_session(ERROR_ADMIN_DEMO, 'caution');
  53.       zen_redirect(zen_href_link(FILENAME_MAIL, 'mail_sent_to=' . urlencode($mail_sent_to)));
  54.     }
  55.  
  56.     //send message using the zen email function
  57.     //echo'EOF-attachments_list='.$attachment_file.'->'.$attachment_filetype;
  58.     $recip_count=0;
  59.     while (!$mail->EOF) {
  60.       $html_msg['EMAIL_FIRST_NAME'] = $mail->fields['customers_firstname'];
  61.       $html_msg['EMAIL_LAST_NAME']  = $mail->fields['customers_lastname'];
  62.       zen_mail($mail->fields['customers_firstname'] . ' ' . $mail->fields['customers_lastname'], $mail->fields['customers_email_address'], $subject, $message, STORE_NAME, $from, $html_msg, 'direct_email', array('file' => $attachment_file, 'name' => basename($attachment_file), 'mime_type'=>$attachment_filetype) );
  63.       $recip_count++;
  64.       $mail->MoveNext();
  65.     }
  66.     if ($recip_count > 0) {
  67.       $messageStack->add_session(sprintf(NOTICE_EMAIL_SENT_TO, $mail_sent_to .  ' (' . $recip_count . ')'), 'success');
  68.     } else {
  69.       $messageStack->add_session(sprintf(NOTICE_EMAIL_FAILED_SEND, $mail_sent_to .  ' (' . $recip_count . ')'), 'error');
  70.     }
  71.     zen_redirect(zen_href_link(FILENAME_MAIL, 'mail_sent_to=' . urlencode($mail_sent_to) . '&recip_count='. $recip_count ));
  72.   }
  73.  
  74.   if ( EMAIL_ATTACHMENTS_ENABLED && $action == 'preview') {
  75.     // PROCESS UPLOAD ATTACHMENTS
  76.     if (isset($_FILES['upload_file']) && zen_not_null($_FILES['upload_file']) && ($_POST['upload_file'] != 'none')) {
  77.       if ($attachments_obj = new upload('upload_file')) {
  78.         $attachments_obj->set_destination(DIR_WS_ADMIN_ATTACHMENTS . $_POST['attach_dir']);
  79.         if ($attachments_obj->parse() && $attachments_obj->save()) {
  80.           $attachment_file = $_POST['attach_dir'] . $attachments_obj->filename;
  81.           $attachment_fname = $attachments_obj->filename;
  82.           $attachment_filetype= $_FILES['upload_file']['type'];
  83.         }
  84.       }
  85.     }
  86.  
  87.     //DEBUG:
  88.     //$messageStack->add('EOF-attachments_list='.$attachment_file.'->'.$attachment_filetype, 'caution');
  89.   } //end attachments upload
  90.  
  91.   // error detection
  92.   if ($action == 'preview') {
  93.     if (!isset($_POST['customers_email_address']) ) {
  94.       $messageStack->add(ERROR_NO_CUSTOMER_SELECTED, 'error');
  95.     }
  96.  
  97.     if ( !$_POST['subject'] ) {
  98.       $messageStack->add(ERROR_NO_SUBJECT, 'error');
  99.     }
  100.  
  101.     if ( !$_POST['message'] && !$_POST['message_html'] ) {
  102.       $messageStack->add(ENTRY_NOTHING_TO_SEND, 'error');
  103.     }
  104.   }
  105.  
  106. ?>
  107. <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
  108. <html <?php echo HTML_PARAMS; ?>>
  109. <head>
  110. <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
  111. <title><?php echo TITLE; ?></title>
  112. <link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
  113. <link rel="stylesheet" type="text/css" href="includes/cssjsmenuhover.css" media="all" id="hoverJS">
  114. <script language="javascript" src="includes/menu.js"></script>
  115. <script type="text/javascript">
  116. <!--
  117. function init()
  118. {
  119.   cssjsmenu('navbar');
  120.   if (document.getElementById)
  121.   {
  122.     var kill = document.getElementById('hoverJS');
  123.     kill.disabled = true;
  124.   }
  125.   if (typeof _editor_url == "string") HTMLArea.replace('message_html');
  126. }
  127. // -->
  128. </script>
  129. <?php if ($editor_handler != '') include ($editor_handler); ?>
  130. <script language="javascript" type="text/javascript"><!--
  131. var form = "";
  132. var submitted = false;
  133. var error = false;
  134. var error_message = "";
  135.  
  136. function check_select(field_name, field_default, message) {
  137.   if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
  138.     var field_value = form.elements[field_name].value;
  139.  
  140.     if (field_value == field_default) {
  141.       error_message = error_message + "* " + message + "\n";
  142.       error = true;
  143.     }
  144.   }
  145. }
  146. function check_message(msg) {
  147.   if (form.elements['message'] && form.elements['message_html']) {
  148.     var field_value1 = form.elements['message'].value;
  149.     var field_value2 = form.elements['message_html'].value;
  150.  
  151.     if ((field_value1 == '' || field_value1.length < 3) && (field_value2 == '' || field_value2.length < 3)) {
  152.       error_message = error_message + "* " + msg + "\n";
  153.       error = true;
  154.     }
  155.   }
  156. }
  157. function check_input(field_name, field_size, message) {
  158.   if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
  159.     var field_value = form.elements[field_name].value;
  160.  
  161.     if (field_value == '' || field_value.length < field_size) {
  162.       error_message = error_message + "* " + message + "\n";
  163.       error = true;
  164.     }
  165.   }
  166. }
  167. function check_attachments(message) {
  168.   if (form.elements['upload_file'] && (form.elements['upload_file'].type != "hidden") && form.elements['attachment_file'] && (form.elements['attachment_file'].type != "hidden")) {
  169.     var field_value_upload = form.elements['upload_file'].value;
  170.     var field_value_file = form.elements['attachment_file'].value;
  171.  
  172.     if (field_value_upload != '' && field_value_file != '') {
  173.       error_message = error_message + "* " + message + "\n";
  174.       error = true;
  175.     }
  176.   }
  177. }
  178. function check_form(form_name) {
  179.   if (submitted == true) {
  180.     alert("<?php echo JS_ERROR_SUBMITTED; ?>");
  181.     return false;
  182.   }
  183.   error = false;
  184.   form = form_name;
  185.   error_message = "<?php echo JS_ERROR; ?>";
  186.  
  187.   check_select("customers_email_address", "", "<?php echo ERROR_NO_CUSTOMER_SELECTED; ?>");
  188.   check_input('subject','',"<?php echo ERROR_NO_SUBJECT; ?>");
  189.   //  check_message("<?php echo ENTRY_NOTHING_TO_SEND; ?>");
  190.   check_attachments("<?php echo ERROR_ATTACHMENTS; ?>");
  191.  
  192.   if (error == true) {
  193.     alert(error_message);
  194.     return false;
  195.   } else {
  196.     submitted = true;
  197.     return true;
  198.   }
  199. }
  200. //--></script>
  201. </head>
  202. <body onLoad="init()">
  203. <!-- header //-->
  204. <?php require(DIR_WS_INCLUDES . 'header.php'); ?>
  205. <!-- header_eof //-->
  206.  
  207. <!-- body //-->
  208. <table border="0" width="100%" cellspacing="2" cellpadding="2">
  209.   <tr>
  210.     <!-- body_text //-->
  211.     <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
  212.       <tr>
  213.       <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
  214.         <tr>
  215.         <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
  216.         <td class="pageHeading" align="right"><?php echo zen_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
  217.         <td class="main">
  218. <?php
  219.   // toggle switch for editor
  220.   echo TEXT_EDITOR_INFO . zen_draw_form('set_editor_form', FILENAME_MAIL, '', 'get') . '&nbsp;&nbsp;' . zen_draw_pull_down_menu('reset_editor', $editors_pulldown, $current_editor_key, 'onChange="this.form.submit();"') .
  221.   zen_hide_session_id() .
  222.   zen_draw_hidden_field('action', 'set_editor') .
  223.   '</form>';
  224. ?>
  225.         </td>
  226.       </tr>
  227.       </table></td>
  228.     </tr>
  229.     <tr>
  230.       <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
  231. <?php
  232.   if ( ($action == 'preview') && isset($_POST['customers_email_address']) ) {
  233.     $audience_select = get_audience_sql_query(zen_db_input($_POST['customers_email_address']));
  234.     $mail_sent_to = $audience_select['query_name'];
  235. ?>
  236.         <tr>
  237.           <td><table border="0" width="100%" cellpadding="0" cellspacing="2">
  238.             <tr>
  239.               <td class="smallText"><b><?php echo TEXT_CUSTOMER; ?></b>&nbsp;&nbsp;&nbsp;<?php echo $mail_sent_to; ?></td>
  240.             </tr>
  241.             <tr>
  242.               <td class="smallText"><b><?php echo TEXT_FROM; ?></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo htmlspecialchars(stripslashes($_POST['from']), ENT_COMPAT, CHARSET, TRUE); ?></td>
  243.             </tr>
  244.             <tr>
  245.               <td class="smallText"><b><?php echo TEXT_SUBJECT; ?></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo htmlspecialchars(stripslashes($_POST['subject']), ENT_COMPAT, CHARSET, TRUE); ?></td>
  246.             </tr>
  247.             <tr>
  248.               <td class="smallText"><b><hr /><?php echo strip_tags(TEXT_MESSAGE_HTML); ?></b></td>
  249.             </tr>
  250.             <tr>
  251.               <td width="500">
  252. <?php if (EMAIL_USE_HTML != 'true') echo TEXT_WARNING_HTML_DISABLED.'<br />'; ?>
  253. <?php $html_preview = stripslashes($_POST['message_html']); echo (stristr($html_preview, '<br') ? $html_preview : nl2br($html_preview)); ?><hr /></td>
  254.             </tr>
  255.             <tr>
  256.               <td class="smallText"><b><?php echo strip_tags(TEXT_MESSAGE); ?></b><br /></td>
  257.             </tr>
  258.             <tr>
  259.               <td>
  260. <?php
  261.   $message_preview = ((is_null($_POST['message']) || $_POST['message']=='') ? $_POST['message_html'] : $_POST['message'] );
  262.   $message_preview = (stristr($message_preview, '<br') ? $message_preview : nl2br($message_preview));
  263.   $message_preview = str_replace(array('<br>','<br />'), "<br />\n", $message_preview);
  264.   $message_preview = str_replace('</p>', "</p>\n", $message_preview);
  265.   echo '<tt>' . nl2br(htmlspecialchars(stripslashes(strip_tags($message_preview)), ENT_COMPAT, CHARSET, TRUE) ) . '</tt>';
  266. ?>
  267.                 <hr />
  268.               </td>
  269.             </tr>
  270. <?php if (EMAIL_ATTACHMENTS_ENABLED && ($upload_file_name != '' || $attachment_file != '')) { ?>
  271.             <tr>
  272.               <td class="smallText"><b><?php echo TEXT_ATTACHMENTS_LIST; ?></b><?php echo '&nbsp;&nbsp;&nbsp;' . ((EMAIL_ATTACHMENT_UPLOADS_ENABLED && zen_not_null($upload_file_name)) ? $upload_file_name : $attachment_file) ; ?></td>
  273.             </tr>
  274. <?php } ?>
  275.             <tr>
  276.               <td><?php echo zen_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  277.             </tr>
  278.             <tr><?php echo zen_draw_form('mail', FILENAME_MAIL, 'action=send_email_to_user'); ?>
  279.               <td>
  280. <?php
  281.   /* Re-Post all POST'ed variables */
  282.   reset($_POST);
  283.   while (list($key, $value) = each($_POST)) {
  284.     if (!is_array($_POST[$key])) {
  285.       echo zen_draw_hidden_field($key, stripslashes($value));
  286.     }
  287.   }
  288.   echo zen_draw_hidden_field('upload_file', stripslashes($upload_file_name));
  289.   echo zen_draw_hidden_field('attachment_file', $attachment_file);
  290.   echo zen_draw_hidden_field('attachment_filetype', $attachment_filetype);
  291. ?>
  292.                 <table border="0" width="100%" cellpadding="0" cellspacing="2">
  293.                   <tr>
  294.                     <td><?php echo zen_image_submit('button_back.gif', IMAGE_BACK, 'name="back"'); ?></td>
  295.                     <td align="right"><?php echo '<a href="' . zen_href_link(FILENAME_MAIL) . '">' . zen_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a> ' . zen_image_submit('button_send_mail.gif', IMAGE_SEND_EMAIL); ?></td>
  296.                   </tr>
  297.                 </table></td>
  298.               </tr>
  299.               </table></td>
  300.             </form></tr>
  301. <?php
  302. } else {
  303. ?>
  304.             <tr><?php echo zen_draw_form('mail', FILENAME_MAIL,'action=preview','post', 'onsubmit="return check_form(mail);" enctype="multipart/form-data"'); ?>
  305.               <td><table border="0" cellpadding="0" cellspacing="2">
  306.             <tr>
  307.               <td colspan="2"><?php echo zen_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  308.             </tr>
  309. <?php
  310.   $customers = get_audiences_list('email');
  311. ?>
  312.             <tr>
  313.               <td class="main"><?php echo TEXT_CUSTOMER; ?></td>
  314.               <td><?php echo zen_draw_pull_down_menu('customers_email_address', $customers, (isset($_GET['customer']) ? $_GET['customer'] : ''));  //, 'multiple' ?></td>
  315.             </tr>
  316.             <tr>
  317.               <td colspan="2"><?php echo zen_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  318.             </tr>
  319.             <tr>
  320.               <td class="main"><?php echo TEXT_FROM; ?></td>
  321.               <td><?php echo zen_draw_input_field('from', htmlspecialchars(EMAIL_FROM, ENT_COMPAT, CHARSET, TRUE), 'size="50"'); ?></td>
  322.             </tr>
  323.             <tr>
  324.               <td colspan="2"><?php echo zen_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  325.             </tr>
  326.             <tr>
  327.               <td class="main"><?php echo TEXT_SUBJECT; ?></td>
  328.               <td><?php echo zen_draw_input_field('subject', htmlspecialchars($_POST['subject'], ENT_COMPAT, CHARSET, TRUE), 'size="50"'); ?></td>
  329.             </tr>
  330.             <tr>
  331.               <td colspan="2"><?php echo zen_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  332.             </tr>
  333.             <tr>
  334.               <td valign="top" class="main"><?php echo TEXT_MESSAGE_HTML; //HTML version?></td>
  335.               <td class="main" width="750">
  336. <?php if (EMAIL_USE_HTML != 'true') echo TEXT_WARNING_HTML_DISABLED; ?>
  337. <?php if (EMAIL_USE_HTML == 'true') {
  338.   echo zen_draw_textarea_field('message_html', 'soft', '100%', '25', htmlspecialchars(stripslashes($_POST['message_html']), ENT_COMPAT, CHARSET, TRUE), 'id="message_html"');
  339. } ?>
  340.               </td>
  341.             </tr>
  342.             <tr>
  343.               <td colspan="2"><?php echo zen_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  344.             </tr>
  345.             <tr>
  346.               <td valign="top" class="main"><?php echo TEXT_MESSAGE; ?></td>
  347.               <td><?php echo zen_draw_textarea_field('message', 'soft', '100%', '15', htmlspecialchars($_POST['message'], ENT_COMPAT, CHARSET, TRUE)); ?></td>
  348.             </tr>
  349.  
  350. <?php if (defined('EMAIL_ATTACHMENTS_ENABLED') && EMAIL_ATTACHMENTS_ENABLED === true && defined('DIR_WS_ADMIN_ATTACHMENTS') && is_dir(DIR_WS_ADMIN_ATTACHMENTS) && is_writable(DIR_WS_ADMIN_ATTACHMENTS) ) { ?>
  351.             <tr>
  352.               <td colspan="2"><?php echo zen_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  353.             </tr>
  354. <?php if (defined('EMAIL_ATTACHMENT_UPLOADS_ENABLED') && EMAIL_ATTACHMENT_UPLOADS_ENABLED === true) { ?>
  355. <?php
  356.   $dir = @dir(DIR_WS_ADMIN_ATTACHMENTS);
  357.   $dir_info[] = array('id' => '', 'text' => "admin-attachments");
  358.   while ($file = $dir->read()) {
  359.     if (is_dir(DIR_WS_ADMIN_ATTACHMENTS . $file) && strtoupper($file) != 'CVS' && $file != "." && $file != "..") {
  360.       $dir_info[] = array('id' => $file . '/', 'text' => $file);
  361.     }
  362.   }
  363.   $dir->close();
  364. ?>
  365.             <tr>
  366.               <td class="main" valign="top"><?php echo TEXT_SELECT_ATTACHMENT_TO_UPLOAD; ?></td>
  367.               <td class="main"><?php echo zen_draw_file_field('upload_file') . '<br />' . stripslashes($_POST['upload_file']) . zen_draw_hidden_field('prev_upload_file', stripslashes( $_POST['upload_file']) ); ?><br />
  368. <?php echo TEXT_ATTACHMENTS_DIR; ?>&nbsp;<?php echo zen_draw_pull_down_menu('attach_dir', $dir_info); ?></td>
  369.             </tr>
  370.             <tr>
  371.               <td colspan="2"><?php echo zen_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  372.             </tr>
  373. <?php  } // end uploads-enabled dialog ?>
  374. <?php
  375.   $dir = @dir(DIR_WS_ADMIN_ATTACHMENTS);
  376.   $file_list[] = array('id' => '', 'text' => "(none)");
  377.   while ($file = $dir->read()) {
  378.     if (is_file(DIR_WS_ADMIN_ATTACHMENTS . $file) && strtoupper($file) != 'CVS' && $file != "." && $file != "..") {
  379.       $file_list[] = array('id' => $file , 'text' => $file);
  380.     }
  381.   }
  382.   $dir->close();
  383. ?>
  384.             <tr>
  385.               <td class="main" valign="top"><?php echo TEXT_SELECT_ATTACHMENT; ?></td>
  386.               <td class="main"><?php echo zen_draw_pull_down_menu('attachment_file', $file_list, $_POST['attachment_file']); ?></td>
  387.             </tr>
  388. <?php } // end attachments fields ?>
  389.             <tr>
  390.               <td colspan="2"><?php echo zen_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  391.             </tr>
  392. <?php
  393.   if (isset($_GET['origin'])) {
  394.     $origin = $_GET['origin'];
  395.   } else {
  396.     $origin = FILENAME_DEFAULT;
  397.   }
  398.   if (isset($_GET['mode']) && $_GET['mode'] == 'SSL') {
  399.     $mode = 'SSL';
  400.   } else {
  401.     $mode = 'NONSSL';
  402.   }
  403. ?>
  404.             <tr>
  405.               <td colspan="2" align="right"><?php echo zen_image_submit('button_preview.gif', IMAGE_PREVIEW) . '&nbsp;' .
  406.               '<a href="' . zen_href_link($origin, 'cID=' . zen_db_prepare_input($_GET['cID']), $mode) . '">' . zen_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>'; ?></td>
  407.             </tr>
  408.           </table></td>
  409.         </form></tr>
  410. <?php
  411. }
  412. ?>
  413. <!-- body_text_eof //-->
  414.       </table></td>
  415.     </tr>
  416.   </table></td>
  417. </tr>
  418. </table>
  419. <!-- body_eof //-->
  420.  
  421. <!-- footer //-->
  422. <?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
  423. <!-- footer_eof //-->
  424. <br />
  425. </body>
  426. </html>
  427. <?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>