Projekt

Allgemein

Profil

Statistiken
| Revision:

testmodus / inc / xtc_php_mail.inc.php @ 1

Historie | Anzeigen | Annotieren | Download (11,8 KB)

1 1 root
<?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
  // includes main class
38
  if (!is_object($main)) {
39
    require_once(DIR_FS_CATALOG.'includes/classes/main.php');
40
    $main = new main();
41
  }
42
43
  if (!class_exists('Smarty')) {
44
    require (DIR_FS_EXTERNAL.'smarty/smarty_2/Smarty.class.php');
45
  }
46
  $mailsmarty= new Smarty;
47
  $mailsmarty->compile_dir = DIR_FS_CATALOG.'templates_c';
48
49
  //set language parameters
50
  $lang_data = array();
51
  $lang_data['directory'] = isset($_SESSION['language']) ? $_SESSION['language'] : '';
52
  $lang_data['language_charset'] = isset($_SESSION['language_charset']) ? $_SESSION['language_charset'] : '';
53
  $lang_data['code'] = isset($_SESSION['language_code']) ? $_SESSION['language_code'] : '';
54
  $lang_data['languages_id'] = isset($_SESSION['languages_id']) ? $_SESSION['languages_id'] : '';
55
  $where= '';
56
  if (empty($lang_data['directory']) || empty($lang_data['language_charset']) || empty($lang_data['code'])) {
57
     $where = " WHERE code = '".DEFAULT_LANGUAGE."'";
58
  }
59
  if (isset($order) && is_object($order)) {
60
    $where = " WHERE directory = '".$order->info['language']."'";
61
    $customers_status = $order->info['status'];
62
  }
63
64
  if ($where) {
65
    $lang_query = xtc_db_query("SELECT *
66
                                  FROM ".TABLE_LANGUAGES."
67
                                  ".$where."
68
                               ");
69
    $lang_data = xtc_db_fetch_array($lang_query);
70
  }
71
72
  // set parameters
73
  $from_email_address = parse_multi_language_value($from_email_address, $lang_data['code']);
74
  $from_email_name = parse_multi_language_value($from_email_name, $lang_data['code']);
75
  $to_email_address = parse_multi_language_value($to_email_address, $lang_data['code']);
76
  $to_name = parse_multi_language_value($to_name, $lang_data['code']);
77
  $forwarding_to = parse_multi_language_value($forwarding_to, $lang_data['code']);
78
  $reply_address = parse_multi_language_value($reply_address, $lang_data['code']);
79
  $reply_address_name = parse_multi_language_value($reply_address_name, $lang_data['code']);
80
  $path_to_attachments = parse_multi_language_value($path_to_attachments, $lang_data['code']);
81
  $email_subject = parse_multi_language_value($email_subject, $lang_data['code']);
82
83
  // load the signatures only, if the appropriate file(s) exists
84
  $html_signatur = '';
85
  $txt_signatur = '';
86
  if (file_exists(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/mail/'.$lang_data['directory'].'/signatur.html')) {
87
    $shop_content_data = $main->getContentData(EMAIL_SIGNATURE_ID, $lang_data['languages_id'], ((isset($customers_status)) ? $customers_status : DEFAULT_CUSTOMERS_STATUS_ID_GUEST));
88
    $mailsmarty->assign('SIGNATURE_HTML', $shop_content_data['content_text']);
89
    $html_signatur = $mailsmarty->fetch(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/mail/'.$lang_data['directory'].'/signatur.html');
90
  }
91
  if (file_exists(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/mail/'.$lang_data['directory'].'/signatur.txt')) {
92
    $shop_content_data = $main->getContentData(EMAIL_SIGNATURE_ID, $lang_data['languages_id'], ((isset($customers_status)) ? $customers_status : DEFAULT_CUSTOMERS_STATUS_ID_GUEST));
93
    $mailsmarty->assign('SIGNATURE_TXT', $shop_content_data['content_text']);
94
    $txt_signatur = $mailsmarty->fetch(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/mail/'.$lang_data['directory'].'/signatur.txt');
95
  }
96
97
  $html_widerruf = '';
98
  $txt_widerruf = '';
99
  if (file_exists(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/mail/'.$lang_data['directory'].'/widerruf.html')) {
100
    $html_widerruf = $mailsmarty->fetch(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/mail/'.$lang_data['directory'].'/widerruf.html');
101
  }
102
  if (file_exists(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/mail/'.$lang_data['directory'].'/widerruf.txt')) {
103
    $txt_widerruf = $mailsmarty->fetch(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/mail/'.$lang_data['directory'].'/widerruf.txt');
104
  }
105
106
  //Platzhalter [WIDERRUF] durch Widerruf Text ersetzen
107
  if (strpos($message_body_html,'[WIDERRUF]') !== false) {
108
    $message_body_html = str_replace('[WIDERRUF]', $html_widerruf, $message_body_html);
109
  } elseif ($html_widerruf != '') {
110
    $html_widerruf = '<br />'.$html_widerruf;
111
  }
112
  if (strpos($message_body_plain,'[WIDERRUF]') !== false) {
113
    $message_body_plain = str_replace('[WIDERRUF]', $txt_widerruf, $message_body_plain);
114
  } elseif ($txt_widerruf != '') {
115
    $txt_widerruf = "\n".$txt_widerruf;
116
  }
117
118
  //Platzhalter [NOSIGNATUR] falls keine Signatir notwendig (zB Newsletter)
119
  if (strpos($message_body_html,'[NOSIGNATUR]') !== false) {
120
    $message_body_html = str_replace('[NOSIGNATUR]', '', $message_body_html);
121
    $message_body_plain = str_replace('[NOSIGNATUR]', '', $message_body_plain);
122
    $html_signatur = '';
123
    $txt_signatur = '';
124
  }
125
126
  //Platzhalter [SIGNATUR] durch Signatur Text ersetzen
127
  if (strpos($message_body_html,'[SIGNATUR]') !== false) {
128
    $message_body_html = str_replace('[SIGNATUR]', $html_signatur, $message_body_html);
129
    $html_signatur = '';
130
  } elseif ($html_signatur != '') {
131
    $html_signatur = '<br />'.$html_signatur;
132
  }
133
  if (strpos($message_body_plain,'[SIGNATUR]') !== false) {
134
    $message_body_plain = str_replace('[SIGNATUR]', $txt_signatur, $message_body_plain);
135
    $txt_signatur = '';
136
  } elseif ($txt_signatur != '') {
137
    $txt_signatur = "\n".$txt_signatur;
138
  }
139
140
  // decode html2txt
141
  $html_array = array('<br />', '<br/>', '<br>');
142
  $txt_array = array(" \n", " \n", " \n");
143
  $message_body_plain = str_replace($html_array, $txt_array, $message_body_plain.$txt_signatur);//DPW Signatur erg?nzt.
144
145
  // remove html tags
146
  $message_body_plain = strip_tags($message_body_plain);
147
  $message_body_plain = html_entity_decode($message_body_plain, ENT_NOQUOTES, $lang_data['language_charset']);
148
149
  require_once (DIR_FS_EXTERNAL.'phpmailer/PHPMailer.php');
150
  require_once (DIR_FS_EXTERNAL.'phpmailer/Exception.php');
151
152
  $mail = new PHPMailer(false);
153
  $mail->Debugoutput = new LoggingManager(DIR_FS_LOG.'mod_mailer_%s_'.((defined('RUN_MODE_ADMIN')) ? 'admin_' : '').'%s.log', 'mailer', (($LogLevel != '') ? $LogLevel : 'info'));
154
  $mail->CharSet = $lang_data['language_charset'];
155
  $mail->Priority = $priority;
156
  $mail->UseSendmailOptions = ((defined('USE_SENDMAIL_OPTIONS') && USE_SENDMAIL_OPTIONS != 'true') ? false : true);
157
158
  if (EMAIL_TRANSPORT == 'smtp') {
159
    require_once (DIR_FS_EXTERNAL.'phpmailer/SMTP.php');
160
161
    $mail->IsSMTP();
162
    $mail->SMTPKeepAlive = true;
163
    $mail->SMTPAuth = (SMTP_AUTH == 'true') ? true : false;
164
    $mail->SMTPSecure = (defined('SMTP_SECURE') && SMTP_SECURE != 'none') ? SMTP_SECURE : '';
165
    $mail->Port = SMTP_PORT;
166
    $mail->Username = SMTP_USERNAME;
167
    $mail->Password = SMTP_PASSWORD;
168
    $mail->Host = SMTP_MAIN_SERVER.';'.SMTP_BACKUP_SERVER;
169
    $mail->SMTPAutoTLS = (defined('SMTP_AUTO_TLS') && SMTP_AUTO_TLS == 'true') ? true : false;
170
    $mail->SMTPDebug = (defined('SMTP_DEBUG')) ? (int)SMTP_DEBUG : 0;
171
    $mail->SMTPOptions = array(
172
      'ssl' => array(
173
        'verify_peer' => false,
174
        'verify_peer_name' => false,
175
        'allow_self_signed' => true
176
      )
177
    );
178
  }
179
180
  if (EMAIL_TRANSPORT == 'sendmail') {
181
    $mail->isSendmail();
182
    $mail->Sendmail = SENDMAIL_PATH;
183
  }
184
185
  if (EMAIL_TRANSPORT == 'mail') {
186
    $mail->isMail();
187
  }
188
189
  //Recipients
190
  $mail->setFrom($from_email_address, $from_email_name);
191
  $mail->addAddress($to_email_address, $to_name);
192
  $mail->addReplyTo($reply_address, $reply_address_name);
193
194
  if ($forwarding_to != '') {
195
    $forwarding = explode(',', $forwarding_to);
196
    foreach ($forwarding as $forwarding_address) {
197
      $mail->addBCC(trim($forwarding_address));
198
    }
199
  }
200
  if (defined('EMAIL_ARCHIVE_ADDRESS')) {
201
    $email_archive_address = parse_multi_language_value(trim(EMAIL_ARCHIVE_ADDRESS), $lang_data['code']);
202
    if (trim($email_archive_address) != '') {
203
      $mail->addBCC(trim($email_archive_address));
204
    }
205
  }
206
207
  //create attachments array for better handling
208
  $attachments = attachments_array($path_to_attachments,$path_to_more_attachments);
209
210
  $included_files = get_included_files();
211
  if (is_array($included_files)) {
212
    $conditions = CONTENT_CONDITIONS;
213
    if (defined('RUN_MODE_ADMIN') && GROUP_CHECK == 'true') {
214
      $conditions = " AND group_ids LIKE '%c_".((isset($customers_status)) ? $customers_status : DEFAULT_CUSTOMERS_STATUS_ID_GUEST)."_group%' ";
215
    }
216
    $email_query = xtc_db_query("SELECT *
217
                                   FROM ".TABLE_EMAIL_CONTENT."
218
                                  WHERE languages_id = '".$lang_data['languages_id']."'
219
                                        ".$conditions);
220
    while ($email = xtc_db_fetch_array($email_query)) {
221
      foreach ($included_files as $files) {
222
        if (strpos($files, $email['email_id'].'.html') !== false) {
223
          if (is_file(DIR_FS_CATALOG.'media/content/'.$email['content_file'])) {
224
            $attachments[] = DIR_FS_CATALOG.'media/content/'.$email['content_file'];
225
          }
226
        }
227
      }
228
    }
229
  }
230
  $attachments = array_unique($attachments);
231
232
  // add attachments
233
  for( $i = 0, $n = count($attachments); $i < $n; $i++) {
234
    $mail->addAttachment($attachments[$i]);
235
  }
236
237
  //Content
238
  $mail->Subject = encode_utf8($email_subject);
239
  $mail->setWordWrap((int)EMAIL_WORD_WRAP);
240
  if (EMAIL_USE_HTML == 'true') { // set email format to HTML
241
    $mail->IsHTML(true);
242
    $mail->Body = $message_body_html.$html_signatur;//DPW Signatur erg?nzt.
243
    $mail->AltBody = $message_body_plain;
244
  } else {
245
    $mail->IsHTML(false);
246
    $mail->Body = $message_body_plain;
247
  }
248
249
  require_once(DIR_FS_INC.'auto_include.inc.php');
250
  foreach(auto_include(DIR_FS_CATALOG.'includes/extra/php_mail/','php') as $file) require ($file);
251
252
  if (!$mail->Send()) {
253
    trigger_error('Mailer Error - '.$mail->ErrorInfo, E_USER_WARNING);
254
    return false;
255
  }
256
  return true;
257
}
258
259
function attachments_array($path_to_attachments,$path_to_more_attachments)
260
{
261
  $attachments = array();
262
  $attachments = check_attachments($attachments,$path_to_attachments);
263
  $attachments = check_attachments($attachments,$path_to_more_attachments);
264
  return $attachments;
265
}
266
267
function check_attachments($attachments, $path_to_attachments)
268
{
269
  if ($path_to_attachments != '') {
270
    $path_to_attachments = is_array($path_to_attachments) ? $path_to_attachments : explode(',',$path_to_attachments);
271
    $num = count($path_to_attachments);
272
    for($i=0; $i <$num; $i++) {
273
      $path_to_attachments[$i] = ((strpos($path_to_attachments[$i], DIR_FS_DOCUMENT_ROOT)===false) ? DIR_FS_DOCUMENT_ROOT:'') . trim($path_to_attachments[$i]);
274
      if (file_exists($path_to_attachments[$i])) {
275
        $attachments[] = $path_to_attachments[$i];
276
      }
277
    }
278
  }
279
  return $attachments;
280
}
281
?>