Projekt

Allgemein

Profil

Statistiken
| Revision:

testmodus / inc / xtc_php_mail.inc.php

Historie | Anzeigen | Annotieren | Download (12,1 KB)

1
<?php
2
/* -----------------------------------------------------------------------------------------
3
   $Id: xtc_php_mail.inc.php 13147 2021-01-11 16:00:32Z GTB $
4

5
   modified eCommerce Shopsoftware
6
   http://www.modified-shop.org
7

8
   Copyright (c) 2009 - 2013 [www.modified-shop.org]
9
   -----------------------------------------------------------------------------------------
10
   based on:
11
   (c) 2003 nextcommerce (xtc_php_mail.inc.php,v 1.17 2003/08/24); www.nextcommerce.org
12
   (c) 2006 XT-Commerce (xtc_php_mail.inc.php)
13

14
   Released under the GNU General Public License
15
   ---------------------------------------------------------------------------------------*/
16

    
17
use PHPMailer\PHPMailer\PHPMailer;
18
use PHPMailer\PHPMailer\Exception;
19

    
20
require_once(DIR_FS_CATALOG.'includes/classes/class.logger.php');
21

    
22
// include the mail classes
23
function xtc_php_mail($from_email_address, $from_email_name,
24
                      $to_email_address, $to_name, $forwarding_to,
25
                      $reply_address, $reply_address_name,
26
                      $path_to_attachments, $path_to_more_attachments,
27
                      $email_subject, $message_body_html, $message_body_plain,
28
                      $priority = null
29
                     )
30
{
31
  global $order, $main, $LogLevel;
32

    
33
  // include needed function
34
  require_once(DIR_FS_INC.'xtc_not_null.inc.php');
35
  require_once(DIR_FS_INC.'parse_multi_language_value.inc.php');
36
  
37
  # TESTMODUS
38
  if(defined('TESTMODUS') && TESTMODUS && EMAIL_CATCH_ALL){
39
    $email_subject = str_replace("::", "::(Testmodus: Umleitung von $to_email_address) - ", $email_subject);
40
    $to_email_address = EMAIL_CATCH_ALL;
41
    $forwarding_to = EMAIL_CATCH_ALL;
42
  }  
43
  
44
  // includes main class
45
  if (!is_object($main)) {
46
    require_once(DIR_FS_CATALOG.'includes/classes/main.php');
47
    $main = new main();
48
  }
49

    
50
  if (!class_exists('Smarty')) {
51
    require (DIR_FS_EXTERNAL.'smarty/smarty_2/Smarty.class.php');
52
  }
53
  $mailsmarty= new Smarty;
54
  $mailsmarty->compile_dir = DIR_FS_CATALOG.'templates_c';
55
  
56
  //set language parameters
57
  $lang_data = array();
58
  $lang_data['directory'] = isset($_SESSION['language']) ? $_SESSION['language'] : '';
59
  $lang_data['language_charset'] = isset($_SESSION['language_charset']) ? $_SESSION['language_charset'] : '';
60
  $lang_data['code'] = isset($_SESSION['language_code']) ? $_SESSION['language_code'] : '';
61
  $lang_data['languages_id'] = isset($_SESSION['languages_id']) ? $_SESSION['languages_id'] : '';
62
  $where= '';
63
  if (empty($lang_data['directory']) || empty($lang_data['language_charset']) || empty($lang_data['code'])) {
64
     $where = " WHERE code = '".DEFAULT_LANGUAGE."'";
65
  }
66
  if (isset($order) && is_object($order)) {
67
    $where = " WHERE directory = '".$order->info['language']."'";
68
    $customers_status = $order->info['status'];
69
  }
70

    
71
  if ($where) {
72
    $lang_query = xtc_db_query("SELECT * 
73
                                  FROM ".TABLE_LANGUAGES." 
74
                                  ".$where."
75
                               ");
76
    $lang_data = xtc_db_fetch_array($lang_query);
77
  }
78
  
79
  // set parameters
80
  $from_email_address = parse_multi_language_value($from_email_address, $lang_data['code']);
81
  $from_email_name = parse_multi_language_value($from_email_name, $lang_data['code']);
82
  $to_email_address = parse_multi_language_value($to_email_address, $lang_data['code']);
83
  $to_name = parse_multi_language_value($to_name, $lang_data['code']);
84
  $forwarding_to = parse_multi_language_value($forwarding_to, $lang_data['code']);
85
  $reply_address = parse_multi_language_value($reply_address, $lang_data['code']);
86
  $reply_address_name = parse_multi_language_value($reply_address_name, $lang_data['code']);
87
  $path_to_attachments = parse_multi_language_value($path_to_attachments, $lang_data['code']);
88
  $email_subject = parse_multi_language_value($email_subject, $lang_data['code']);
89
      
90
  // load the signatures only, if the appropriate file(s) exists
91
  $html_signatur = '';
92
  $txt_signatur = '';
93
  if (file_exists(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/mail/'.$lang_data['directory'].'/signatur.html')) {
94
    $shop_content_data = $main->getContentData(EMAIL_SIGNATURE_ID, $lang_data['languages_id'], ((isset($customers_status)) ? $customers_status : DEFAULT_CUSTOMERS_STATUS_ID_GUEST));    
95
    $mailsmarty->assign('SIGNATURE_HTML', $shop_content_data['content_text']);
96
    $html_signatur = $mailsmarty->fetch(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/mail/'.$lang_data['directory'].'/signatur.html'); 
97
  }
98
  if (file_exists(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/mail/'.$lang_data['directory'].'/signatur.txt')) {
99
    $shop_content_data = $main->getContentData(EMAIL_SIGNATURE_ID, $lang_data['languages_id'], ((isset($customers_status)) ? $customers_status : DEFAULT_CUSTOMERS_STATUS_ID_GUEST));
100
    $mailsmarty->assign('SIGNATURE_TXT', $shop_content_data['content_text']);
101
    $txt_signatur = $mailsmarty->fetch(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/mail/'.$lang_data['directory'].'/signatur.txt'); 
102
  }
103

    
104
  $html_widerruf = '';
105
  $txt_widerruf = '';
106
  if (file_exists(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/mail/'.$lang_data['directory'].'/widerruf.html')) {
107
    $html_widerruf = $mailsmarty->fetch(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/mail/'.$lang_data['directory'].'/widerruf.html'); 
108
  }
109
  if (file_exists(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/mail/'.$lang_data['directory'].'/widerruf.txt')) {
110
    $txt_widerruf = $mailsmarty->fetch(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/mail/'.$lang_data['directory'].'/widerruf.txt'); 
111
  }  
112

    
113
  //Platzhalter [WIDERRUF] durch Widerruf Text ersetzen
114
  if (strpos($message_body_html,'[WIDERRUF]') !== false) {
115
    $message_body_html = str_replace('[WIDERRUF]', $html_widerruf, $message_body_html);
116
  } elseif ($html_widerruf != '') {
117
    $html_widerruf = '<br />'.$html_widerruf;
118
  }
119
  if (strpos($message_body_plain,'[WIDERRUF]') !== false) {
120
    $message_body_plain = str_replace('[WIDERRUF]', $txt_widerruf, $message_body_plain);
121
  } elseif ($txt_widerruf != '') {
122
    $txt_widerruf = "\n".$txt_widerruf;  
123
  }
124

    
125
  //Platzhalter [NOSIGNATUR] falls keine Signatir notwendig (zB Newsletter)
126
  if (strpos($message_body_html,'[NOSIGNATUR]') !== false) {
127
    $message_body_html = str_replace('[NOSIGNATUR]', '', $message_body_html);
128
    $message_body_plain = str_replace('[NOSIGNATUR]', '', $message_body_plain);
129
    $html_signatur = '';
130
    $txt_signatur = '';
131
  }
132

    
133
  //Platzhalter [SIGNATUR] durch Signatur Text ersetzen
134
  if (strpos($message_body_html,'[SIGNATUR]') !== false) {
135
    $message_body_html = str_replace('[SIGNATUR]', $html_signatur, $message_body_html);
136
    $html_signatur = '';
137
  } elseif ($html_signatur != '') {
138
    $html_signatur = '<br />'.$html_signatur;
139
  }
140
  if (strpos($message_body_plain,'[SIGNATUR]') !== false) {
141
    $message_body_plain = str_replace('[SIGNATUR]', $txt_signatur, $message_body_plain);
142
    $txt_signatur = '';
143
  } elseif ($txt_signatur != '') {
144
    $txt_signatur = "\n".$txt_signatur;  
145
  }
146

    
147
  // decode html2txt
148
  $html_array = array('<br />', '<br/>', '<br>');
149
  $txt_array = array(" \n", " \n", " \n");
150
  $message_body_plain = str_replace($html_array, $txt_array, $message_body_plain.$txt_signatur);//DPW Signatur erg?nzt.
151
  
152
  // remove html tags
153
  $message_body_plain = strip_tags($message_body_plain);
154
  $message_body_plain = html_entity_decode($message_body_plain, ENT_NOQUOTES, $lang_data['language_charset']);
155

    
156
  require_once (DIR_FS_EXTERNAL.'phpmailer/PHPMailer.php');
157
  require_once (DIR_FS_EXTERNAL.'phpmailer/Exception.php');
158

    
159
  $mail = new PHPMailer(false);
160
  $mail->Debugoutput = new LoggingManager(DIR_FS_LOG.'mod_mailer_%s_'.((defined('RUN_MODE_ADMIN')) ? 'admin_' : '').'%s.log', 'mailer', (($LogLevel != '') ? $LogLevel : 'info'));
161
  $mail->CharSet = $lang_data['language_charset'];
162
  $mail->Priority = $priority;
163
  $mail->UseSendmailOptions = ((defined('USE_SENDMAIL_OPTIONS') && USE_SENDMAIL_OPTIONS != 'true') ? false : true);
164
  
165
  if (EMAIL_TRANSPORT == 'smtp') {
166
    require_once (DIR_FS_EXTERNAL.'phpmailer/SMTP.php');
167
    
168
    $mail->IsSMTP();
169
    $mail->SMTPKeepAlive = true;
170
    $mail->SMTPAuth = (SMTP_AUTH == 'true') ? true : false;
171
    $mail->SMTPSecure = (defined('SMTP_SECURE') && SMTP_SECURE != 'none') ? SMTP_SECURE : '';
172
    $mail->Port = SMTP_PORT;
173
    $mail->Username = SMTP_USERNAME;
174
    $mail->Password = SMTP_PASSWORD;
175
    $mail->Host = SMTP_MAIN_SERVER.';'.SMTP_BACKUP_SERVER;
176
    $mail->SMTPAutoTLS = (defined('SMTP_AUTO_TLS') && SMTP_AUTO_TLS == 'true') ? true : false;
177
    $mail->SMTPDebug = (defined('SMTP_DEBUG')) ? (int)SMTP_DEBUG : 0;
178
    $mail->SMTPOptions = array(
179
      'ssl' => array(
180
        'verify_peer' => false,
181
        'verify_peer_name' => false,
182
        'allow_self_signed' => true
183
      )
184
    );
185
  }
186

    
187
  if (EMAIL_TRANSPORT == 'sendmail') {
188
    $mail->isSendmail();
189
    $mail->Sendmail = SENDMAIL_PATH;
190
  }
191

    
192
  if (EMAIL_TRANSPORT == 'mail') {
193
    $mail->isMail();
194
  }
195

    
196
  //Recipients
197
  $mail->setFrom($from_email_address, $from_email_name);
198
  $mail->addAddress($to_email_address, $to_name);
199
  $mail->addReplyTo($reply_address, $reply_address_name);
200

    
201
  if ($forwarding_to != '') {
202
    $forwarding = explode(',', $forwarding_to);
203
    foreach ($forwarding as $forwarding_address) {
204
      $mail->addBCC(trim($forwarding_address));
205
    }
206
  }
207
  if (defined('EMAIL_ARCHIVE_ADDRESS')) {
208
    $email_archive_address = parse_multi_language_value(trim(EMAIL_ARCHIVE_ADDRESS), $lang_data['code']);
209
    if (trim($email_archive_address) != '') {
210
      $mail->addBCC(trim($email_archive_address));
211
    }
212
  }
213

    
214
  //create attachments array for better handling
215
  $attachments = attachments_array($path_to_attachments,$path_to_more_attachments);
216
  
217
  $included_files = get_included_files();
218
  if (is_array($included_files)) {
219
    $conditions = CONTENT_CONDITIONS;
220
    if (defined('RUN_MODE_ADMIN') && GROUP_CHECK == 'true') {
221
      $conditions = " AND group_ids LIKE '%c_".((isset($customers_status)) ? $customers_status : DEFAULT_CUSTOMERS_STATUS_ID_GUEST)."_group%' ";
222
    }
223
    $email_query = xtc_db_query("SELECT *
224
                                   FROM ".TABLE_EMAIL_CONTENT."
225
                                  WHERE languages_id = '".$lang_data['languages_id']."'
226
                                        ".$conditions);
227
    while ($email = xtc_db_fetch_array($email_query)) {
228
      foreach ($included_files as $files) {
229
        if (strpos($files, $email['email_id'].'.html') !== false) {
230
          if (is_file(DIR_FS_CATALOG.'media/content/'.$email['content_file'])) {
231
            $attachments[] = DIR_FS_CATALOG.'media/content/'.$email['content_file'];
232
          }
233
        }
234
      }
235
    }
236
  }
237
  $attachments = array_unique($attachments); 
238

    
239
  // add attachments
240
  for( $i = 0, $n = count($attachments); $i < $n; $i++) {
241
    $mail->addAttachment($attachments[$i]);
242
  }
243

    
244
  //Content
245
  $mail->Subject = encode_utf8($email_subject);
246
  $mail->setWordWrap((int)EMAIL_WORD_WRAP);
247
  if (EMAIL_USE_HTML == 'true') { // set email format to HTML
248
    $mail->IsHTML(true);
249
    $mail->Body = $message_body_html.$html_signatur;//DPW Signatur erg?nzt.
250
    $mail->AltBody = $message_body_plain;
251
  } else {
252
    $mail->IsHTML(false);
253
    $mail->Body = $message_body_plain;
254
  }
255

    
256
  require_once(DIR_FS_INC.'auto_include.inc.php');
257
  foreach(auto_include(DIR_FS_CATALOG.'includes/extra/php_mail/','php') as $file) require ($file);
258

    
259
  if (!$mail->Send()) {
260
    trigger_error('Mailer Error - '.$mail->ErrorInfo, E_USER_WARNING);
261
    return false;
262
  }
263
  return true;
264
}
265

    
266
function attachments_array($path_to_attachments,$path_to_more_attachments)
267
{
268
  $attachments = array();
269
  $attachments = check_attachments($attachments,$path_to_attachments);
270
  $attachments = check_attachments($attachments,$path_to_more_attachments);
271
  return $attachments;
272
}
273

    
274
function check_attachments($attachments, $path_to_attachments)
275
{
276
  if ($path_to_attachments != '') {
277
    $path_to_attachments = is_array($path_to_attachments) ? $path_to_attachments : explode(',',$path_to_attachments);
278
    $num = count($path_to_attachments);
279
    for($i=0; $i <$num; $i++) {
280
      $path_to_attachments[$i] = ((strpos($path_to_attachments[$i], DIR_FS_DOCUMENT_ROOT)===false) ? DIR_FS_DOCUMENT_ROOT:'') . trim($path_to_attachments[$i]);
281
      if (file_exists($path_to_attachments[$i])) {
282
        $attachments[] = $path_to_attachments[$i];
283
      }
284
    }
285
  }
286
  return $attachments;
287
}
288
?>