source: trunk/include/functions_mail.inc.php @ 25360

Last change on this file since 25360 was 25360, checked in by mistic100, 10 years ago

feature 2995: New email template
restore get_l10n_args removed at r25357
apply changes to NBM

  • Property svn:eol-style set to LF
File size: 22.0 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2013 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24/**
25 * Returns the name of the mail sender
26 * @return string
27 */
28function get_mail_sender_name()
29{
30  global $conf;
31
32  return (empty($conf['mail_sender_name']) ? $conf['gallery_title'] : $conf['mail_sender_name']);
33}
34
35/**
36 * Returns the email of the mail sender
37 * @since 2.6
38 * @return string
39 */
40function get_mail_sender_email()
41{
42  global $conf;
43
44  return (empty($conf['mail_sender_email']) ? get_webmaster_mail_address() : $conf['mail_sender_email']);
45}
46
47/**
48 * Returns an array of mail configuration parameters :
49 * - send_bcc_mail_webmaster
50 * - mail_allow_html
51 * - use_smtp
52 * - smtp_host
53 * - smtp_user
54 * - smtp_password
55 * - smtp_secure
56 * - email_webmaster
57 * - name_webmaster
58 *
59 * @return array
60 */
61function get_mail_configuration()
62{
63  global $conf;
64
65  $conf_mail = array(
66    'send_bcc_mail_webmaster' => $conf['send_bcc_mail_webmaster'],
67    'mail_allow_html' => $conf['mail_allow_html'],
68    'mail_theme' => $conf['mail_theme'],
69    'use_smtp' => !empty($conf['smtp_host']),
70    'smtp_host' => $conf['smtp_host'],
71    'smtp_user' => $conf['smtp_user'],
72    'smtp_password' => $conf['smtp_password'],
73    'smtp_secure' => $conf['smtp_secure'],
74    'email_webmaster' => get_mail_sender_email(),
75    'name_webmaster' => get_mail_sender_name(),
76    );
77
78  return $conf_mail;
79}
80
81/**
82 * Returns an email address with an associated real name
83 * @param string name
84 * @param string email
85 */
86function format_email($name, $email)
87{
88  $cvt_email = trim(preg_replace('#[\n\r]+#s', '', $email));
89  $cvt_name = trim(preg_replace('#[\n\r]+#s', '', $name));
90
91  if ($cvt_name!="")
92  {
93    $cvt_name = '"'.addcslashes($cvt_name,'"').'"'.' ';
94  }
95
96  if (strpos($cvt_email, '<') === false)
97  {
98    return $cvt_name.'<'.$cvt_email.'>';
99  }
100  else
101  {
102    return $cvt_name.$cvt_email;
103  }
104}
105
106/**
107 * Returns the mail and the name from a formatted address
108 * @since 2.6
109 * @param string|array $input
110 * @return array
111 */
112function unformat_email($input)
113{
114  if (is_array($input))
115  {
116    return $input;
117  }
118
119  if (preg_match('/(.*)<(.*)>.*/', $input, $matches))
120  {
121    return array(
122      'email' => trim($matches[2]),
123      'name' => trim($matches[1]),
124      );
125  }
126  else
127  {
128    return array(
129      'email' => trim($input),
130      'name' => '',
131      );
132  }
133}
134 
135
136/**
137 * Returns an email address list with minimal email string
138 * @param string $email_list - comma separated
139 * @return string
140 */
141function get_strict_email_list($email_list)
142{
143  $result = array();
144  $list = explode(',', $email_list);
145
146  foreach ($list as $email)
147  {
148    if (strpos($email, '<') !== false)
149    {
150       $email = preg_replace('/.*<(.*)>.*/i', '$1', $email);
151    }
152    $result[] = trim($email);
153  }
154
155  return implode(',', array_unique($result));
156}
157
158
159/**
160 * Return an new mail template
161 * @param string $email_format - text/html or text/plain
162 * @return Template
163 */
164function &get_mail_template($email_format)
165{
166  $template = new Template(PHPWG_ROOT_PATH.'themes', 'default', 'template/mail/'.$email_format);
167  return $template;
168}
169
170/**
171 * Return string email format (text/html or text/plain)
172 * @param bool is_html
173 * @return string
174 */
175function get_str_email_format($is_html)
176{
177  return ($is_html ? 'text/html' : 'text/plain');
178}
179
180/**
181 * Switch language to specified language
182 * All entries are push on language stack
183 * @param string $language
184 */
185function switch_lang_to($language)
186{
187  global $switch_lang, $user, $lang, $lang_info, $language_files;
188
189  // explanation of switch_lang
190  // $switch_lang['language'] contains data of language
191  // $switch_lang['stack'] contains stack LIFO
192  // $switch_lang['initialisation'] allow to know if it's first call
193
194  // Treatment with current user
195  // Language of current user is saved (it's considered OK on firt call)
196  if (!isset($switch_lang['initialisation']) and !isset($switch_lang['language'][$user['language']]))
197  {
198    $switch_lang['initialisation'] = true;
199    $switch_lang['language'][$user['language']]['lang_info'] = $lang_info;
200    $switch_lang['language'][$user['language']]['lang'] = $lang;
201  }
202
203  // Change current infos
204  $switch_lang['stack'][] = $user['language'];
205  $user['language'] = $language;
206
207  // Load new data if necessary
208  if (!isset($switch_lang['language'][$language]))
209  {
210    // Re-Init language arrays
211    $lang_info = array();
212    $lang  = array();
213
214    // language files
215    load_language('common.lang', '', array('language'=>$language) );
216    // No test admin because script is checked admin (user selected no)
217    // Translations are in admin file too
218    load_language('admin.lang', '', array('language'=>$language) );
219   
220    // Reload all plugins files (see load_language declaration)
221    if (!empty($language_files))
222    {
223      foreach ($language_files as $dirname => $files)
224        foreach ($files as $filename)
225          load_language($filename, $dirname, array('language'=>$language) );
226    }
227   
228    trigger_action('loading_lang');
229    load_language('lang', PHPWG_ROOT_PATH.PWG_LOCAL_DIR,
230      array('language'=>$language, 'no_fallback'=>true, 'local'=>true)
231    );
232
233    $switch_lang['language'][$language]['lang_info'] = $lang_info;
234    $switch_lang['language'][$language]['lang'] = $lang;
235  }
236  else
237  {
238    $lang_info = $switch_lang['language'][$language]['lang_info'];
239    $lang = $switch_lang['language'][$language]['lang'];
240  }
241}
242
243/**
244 * Switch back language pushed with switch_lang_to function
245 */
246function switch_lang_back()
247{
248  global $switch_lang, $user, $lang, $lang_info;
249
250  if (count($switch_lang['stack']) > 0)
251  {
252    // Get last value
253    $language = array_pop($switch_lang['stack']);
254
255    // Change current infos
256    if (isset($switch_lang['language'][$language]))
257    {
258      $lang_info = $switch_lang['language'][$language]['lang_info'];
259      $lang = $switch_lang['language'][$language]['lang'];
260    }
261    $user['language'] = $language;
262  }
263}
264
265/**
266 * Send a notification email to all administrators
267 * current user (if admin) is not notified
268 * @param string|array $subject
269 * @param string|array $content
270 * @param boolean $send_technical_details - send user IP and browser
271 * @return boolean
272 */
273function pwg_mail_notification_admins($subject, $content, $send_technical_details=true)
274{
275  if (empty($subject) or empty($content))
276  {
277    return false;
278  }
279
280  global $conf, $user;
281
282  if (is_array($subject) or is_array($content))
283  {
284    switch_lang_to(get_default_language());
285
286    if (is_array($subject))
287    {
288      $subject = l10n_args($subject);
289    }
290    if (is_array($content))
291    {
292      $content = l10n_args($content);
293    }
294
295    switch_lang_back();
296  }
297
298  $tpl_vars = array();
299  if ($send_technical_details)
300  {
301    $tpl_vars['TECHNICAL'] = array(
302      'username' => stripslashes($user['username']),
303      'ip' => $_SERVER['REMOTE_ADDR'],
304      'user_agent' => $_SERVER['HTTP_USER_AGENT'],
305      );
306  }
307
308  return pwg_mail_admins(
309    array(
310      'subject' => '['. $conf['gallery_title'] .'] '. $subject,
311      'mail_title' => $conf['gallery_title'],
312      'mail_subtitle' => $subject,
313      'content' => $content,
314      'content_format' => 'text/plain',
315      ),
316    array(
317      'filename' => 'notification_admin',
318      'assign' => $tpl_vars,
319      )
320    );
321}
322
323/**
324 * Send a email to all administrators
325 * current user (if admin) is excluded
326 * @see pwg_mail()
327 * @since 2.6
328 *
329 * @param array $args - as in pwg_mail()
330 * @param array $tpl - as in pwg_mail()
331 * @return boolean
332 */
333function pwg_mail_admins($args=array(), $tpl=array())
334{
335  if (empty($args['content']) and empty($tpl))
336  {
337    return false;
338  }
339
340  global $conf, $user;
341  $return = true;
342
343  // get admins (except ourself)
344  $query = '
345SELECT
346    u.'.$conf['user_fields']['username'].' AS name,
347    u.'.$conf['user_fields']['email'].' AS email
348  FROM '.USERS_TABLE.' AS u
349    JOIN '.USER_INFOS_TABLE.' AS i
350    ON i.user_id =  u.'.$conf['user_fields']['id'].'
351  WHERE i.status in (\'webmaster\',  \'admin\')
352    AND u.'.$conf['user_fields']['email'].' IS NOT NULL
353    AND i.user_id <> '.$user['id'].'
354  ORDER BY username
355;';
356  $admins = array_from_query($query);
357
358  if (empty($admins))
359  {
360    return $return;
361  }
362
363  switch_lang_to(get_default_language());
364
365  $return = pwg_mail($admins, $args, $tpl);
366
367  switch_lang_back();
368
369  return $return;
370}
371
372/**
373 * Send an email to a group
374 * @see pwg_mail()
375 *
376 * @param int $group_id
377 * @param array $args - as in pwg_mail()
378 *    @option string language_selected - filters users of the group by language
379 * @param array $tpl - as in pwg_mail()
380 * @return boolean
381 */
382function pwg_mail_group($group_id, $args=array(), $tpl=array())
383{ 
384  if (empty($group_id) or ( empty($args['content']) and empty($tpl) ))
385  {
386    return false;
387  }
388
389  global $conf;
390  $return = true;
391
392  // get distinct languages of targeted users
393  $query = '
394SELECT DISTINCT language
395  FROM '.USER_GROUP_TABLE.' AS ug
396    INNER JOIN '.USERS_TABLE.' AS u
397    ON '.$conf['user_fields']['id'].' = ug.user_id
398    INNER JOIN '.USER_INFOS_TABLE.' AS ui
399    ON ui.user_id = ug.user_id
400  WHERE group_id = '.$group_id.'
401    AND '.$conf['user_fields']['email'].' <> ""';
402  if (!empty($args['language_selected']))
403  {
404    $query .= '
405    AND language = \''.$args['language_selected'].'\'';
406  }
407
408    $query .= '
409;';
410  $languages = array_from_query($query, 'language');
411
412  if (empty($languages))
413  {
414    return $return;
415  }
416
417  foreach ($languages as $language)
418  {
419    // get subset of users in this group for a specific language
420    $query = '
421SELECT
422    u.'.$conf['user_fields']['username'].' AS name,
423    u.'.$conf['user_fields']['email'].' AS email
424  FROM '.USER_GROUP_TABLE.' AS ug
425    INNER JOIN '.USERS_TABLE.' AS u
426    ON '.$conf['user_fields']['id'].' = ug.user_id
427    INNER JOIN '.USER_INFOS_TABLE.' AS ui
428    ON ui.user_id = ug.user_id
429  WHERE group_id = '.$group_id.'
430    AND '.$conf['user_fields']['email'].' <> ""
431    AND language = \''.$language.'\'
432;';
433    $users = array_from_query($query);
434
435    if (empty($users))
436    {
437      continue;
438    }
439
440    switch_lang_to($language);
441
442    $return&= pwg_mail(null,
443      array_merge(
444        $args,
445        array('Bcc' => $users)
446        ),
447      $tpl
448      );
449
450    switch_lang_back();
451  }
452
453  return $return;
454}
455
456/**
457 * sends an email, using Piwigo specific informations
458 *
459 * @param string|string[] $to
460 * @param array $args
461 *       o from: sender [default value webmaster email]
462 *       o Cc: array of carbon copy receivers of the mail. [default value empty]
463 *       o Bcc: array of blind carbon copy receivers of the mail. [default value empty]
464 *       o subject [default value 'Piwigo']
465 *       o content: content of mail [default value '']
466 *       o content_format: format of mail content [default value 'text/plain']
467 *       o email_format: global mail format [default value $conf_mail['default_email_format']]
468 *       o theme: theme to use [default value $conf_mail['mail_theme']]
469 *       o mail_title: main title of the mail [default value $conf['gallery_title']]
470 *       o mail_subtitle: subtitle of the mail [default value subject]
471 * @param array $tpl - use these options to define a custom content template file
472 *       o filename
473 *       o dirname (optional)
474 *       o assign (optional)
475 *
476 * @return boolean
477 */
478function pwg_mail($to, $args=array(), $tpl=array())
479{
480  global $conf, $conf_mail, $lang_info, $page;
481
482  if (empty($to) and empty($args['Cc']) and empty($args['Bcc']))
483  {
484    return true;
485  }
486
487  if (!isset($conf_mail))
488  {
489    $conf_mail = get_mail_configuration();
490  }
491
492  include_once(PHPWG_ROOT_PATH.'include/phpmailer/class.phpmailer.php');
493
494  $mail = new PHPMailer;
495
496  $recipients = !is_array($to) ? explode(',', $to) : $to;
497  foreach ($recipients as $recipient)
498  {
499    $recipient = unformat_email($recipient);
500    $mail->addAddress($recipient['email'], $recipient['name']);
501  }
502
503  $mail->WordWrap = 76;
504  $mail->CharSet = 'UTF-8';
505 
506  // Compute root_path in order have complete path
507  set_make_full_url();
508
509  if (empty($args['from']))
510  {
511    $from = array(
512      'email' => $conf_mail['email_webmaster'],
513      'name' => $conf_mail['name_webmaster'],
514      );
515  }
516  else
517  {
518    $from = unformat_email($args['from']);
519  }
520  $mail->setFrom($from['email'], $from['name']);
521  $mail->addReplyTo($from['email'], $from['name']);
522
523  // Subject
524  if (empty($args['subject']))
525  {
526    $args['subject'] = 'Piwigo';
527  }
528  $args['subject'] = trim(preg_replace('#[\n\r]+#s', '', $args['subject']));
529  $mail->Subject = $args['subject'];
530
531  // Cc
532  if (!empty($args['Cc']))
533  {
534    foreach ($args['Cc'] as $cc)
535    {
536      $cc = unformat_email($cc);
537      $mail->addCC($cc['email'], $cc['name']);
538    }
539  }
540
541  // Bcc
542  if ($conf_mail['send_bcc_mail_webmaster'])
543  {
544    $args['Bcc'][] = get_webmaster_mail_address();
545  }
546  if (!empty($args['Bcc']))
547  {
548    foreach ($args['Bcc'] as $bcc)
549    {
550      $bcc = unformat_email($bcc);
551      $mail->addBCC($bcc['email'], $bcc['name']);
552    }
553  }
554
555  // theme
556  if (empty($args['theme']) or !in_array($args['theme'], array('clear','dark')))
557  {
558    $args['theme'] = $conf_mail['mail_theme'];
559  }
560
561  // content
562  if (!isset($args['content']))
563  {
564    $args['content'] = '';
565  }
566 
567  // try to decompose subject like "[....] ...."
568  if (!isset($args['mail_title']) and !isset($args['mail_subtitle']))
569  {
570    if (preg_match('#^\[(.*)\](.*)$#',  $args['subject'], $matches))
571    {
572      $args['mail_title'] = $matches[1];
573      $args['mail_subtitle'] = $matches[2];
574    }
575  }
576  if (!isset($args['mail_title']))
577  {
578    $args['mail_title'] = $conf['gallery_title'];
579  }
580  if (!isset($args['mail_subtitle']))
581  {
582    $args['mail_subtitle'] = $args['subject'];
583  }
584
585  // content type
586  if (empty($args['content_format']))
587  {
588    $args['content_format'] = 'text/plain';
589  }
590
591  $content_type_list = array();
592  if ($conf_mail['mail_allow_html'] and @$args['email_format'] != 'text/plain')
593  {
594    $content_type_list[] = 'text/html';
595  }
596  $content_type_list[] = 'text/plain';
597
598  $contents = array();
599  foreach ($content_type_list as $content_type)
600  {
601    // key compose of indexes witch allow to cache mail data
602    $cache_key = $content_type.'-'.$lang_info['code'];
603
604    if (!isset($conf_mail[$cache_key]))
605    {
606      // instanciate a new Template
607      if (!isset($conf_mail[$cache_key]['theme']))
608      {
609        $conf_mail[$cache_key]['theme'] = get_mail_template($content_type);
610        trigger_action('before_parse_mail_template', $cache_key, $content_type);
611      }
612      $template = &$conf_mail[$cache_key]['theme'];
613
614      $template->set_filename('mail_header', 'header.tpl');
615      $template->set_filename('mail_footer', 'footer.tpl');
616
617      $template->assign(
618        array(
619          'GALLERY_URL' => get_gallery_home_url(),
620          'GALLERY_TITLE' => isset($page['gallery_title']) ? $page['gallery_title'] : $conf['gallery_title'],
621          'VERSION' => $conf['show_version'] ? PHPWG_VERSION : '',
622          'PHPWG_URL' => defined('PHPWG_URL') ? PHPWG_URL : '',
623          'CONTENT_ENCODING' => get_pwg_charset(),
624          'CONTACT_MAIL' => $conf_mail['email_webmaster'],
625          )
626        );
627
628      if ($content_type == 'text/html')
629      {
630        if ($template->smarty->template_exists('global-mail-css.tpl'))
631        {
632          $template->set_filename('css', 'global-mail-css.tpl');
633          $template->assign_var_from_handle('GLOBAL_MAIL_CSS', 'css');
634        }
635
636        if ($template->smarty->template_exists('mail-css-'. $args['theme'] .'.tpl'))
637        {
638          $template->set_filename('css', 'mail-css-'. $args['theme'] .'.tpl');
639          $template->assign_var_from_handle('MAIL_CSS', 'css');
640        }
641      }
642    }
643   
644    $template = &$conf_mail[$cache_key]['theme'];
645    $template->assign(
646      array(
647        'MAIL_TITLE' => $args['mail_title'],
648        'MAIL_SUBTITLE' => $args['mail_subtitle'],
649        )
650      );
651
652    // Header
653    $contents[$content_type] = $template->parse('mail_header', true);
654
655    // Content
656    // Stored in a temp variable, if a content template is used it will be assigned
657    // to the $CONTENT template variable, otherwise it will be appened to the mail
658    if ($args['content_format'] == 'text/plain' and $content_type == 'text/html')
659    {
660      // convert plain text to html
661      $mail_content =
662        '<p>'.
663        nl2br(
664          preg_replace(
665            '/(https?:\/\/([-\w\.]+[-\w])+(:\d+)?(\/([\w\/_\.\#-]*(\?\S+)?[^\.\s])?)?)/i',
666            '<a href="$1">$1</a>',
667            htmlspecialchars($args['content'])
668            )
669          ).
670        '</p>';
671    }
672    else if ($args['content_format'] == 'text/html' and $content_type == 'text/plain')
673    {
674      // convert html text to plain text
675      $mail_content = strip_tags($args['content']);
676    }
677    else
678    {
679      $mail_content = $args['content'];
680    }
681
682    // Runtime template
683    if (isset($tpl['filename']))
684    {
685      if (isset($tpl['dirname']))
686      {
687        $template->set_template_dir($tpl['dirname'] .'/'. $content_type);
688      }
689      if ($template->smarty->template_exists($tpl['filename'] .'.tpl'))
690      {
691        $template->set_filename($tpl['filename'], $tpl['filename'] .'.tpl');
692        if (!empty($tpl['assign']))
693        {
694          $template->assign($tpl['assign']);
695        }
696        $template->assign('CONTENT', $mail_content);
697        $contents[$content_type].= $template->parse($tpl['filename'], true);
698      }
699      else
700      {
701        $contents[$content_type].= $mail_content;
702      }
703    }
704    else
705    {
706      $contents[$content_type].= $mail_content;
707    }
708
709    // Footer
710    $contents[$content_type].= $template->parse('mail_footer', true);
711  }
712
713  // Undo Compute root_path in order have complete path
714  unset_make_full_url();
715
716  // Send content to PHPMailer
717  if (isset($contents['text/html']))
718  {
719    $mail->isHTML(true);
720    $mail->Body = move_css_to_body($contents['text/html']);
721   
722    if (isset($contents['text/plain']))
723    {
724      $mail->AltBody = $contents['text/plain'];
725    }
726  }
727  else
728  {
729    $mail->isHTML(false);
730    $mail->Body = $contents['text/plain'];
731  }
732
733  if ($conf_mail['use_smtp'])
734  {
735    // now we need to split port number
736    if (strpos($conf_mail['smtp_host'], ':') !== false)
737    {
738      list($smtp_host, $smtp_port) = explode(':', $conf_mail['smtp_host']);
739    }
740    else
741    {
742      $smtp_host = $conf_mail['smtp_host'];
743      $smtp_port = 25;
744    }
745
746    $mail->IsSMTP();
747
748    // enables SMTP debug information (for testing) 2 - debug, 0 - no message
749    $mail->SMTPDebug = 0;
750   
751    $mail->Host = $smtp_host;
752    $mail->Port = $smtp_port;
753
754    if (!empty($conf_mail['smtp_secure']) and in_array($conf_mail['smtp_secure'], array('ssl', 'tls')))
755    {
756      $mail->SMTPSecure = $conf_mail['smtp_secure'];
757    }
758   
759    if (!empty($conf_mail['smtp_user']))
760    {
761      $mail->SMTPAuth = true;
762      $mail->Username = $conf_mail['smtp_user'];
763      $mail->Password = $conf_mail['smtp_password'];
764    }
765  }
766
767  $ret = true;
768  $pre_result = trigger_event('before_send_mail', true, $to, $args, $mail);
769
770  if ($pre_result)
771  {
772    $ret = $mail->send();
773    if (!$ret and is_admin())
774    {
775      trigger_error('Mailer Error: ' . $mail->ErrorInfo, E_USER_WARNING);
776    }
777  }
778
779  return $ret;
780}
781
782/**
783 * @deprecated 2.6
784 */
785function pwg_send_mail($result, $to, $subject, $content, $headers)
786{
787  if (is_admin())
788  {
789    trigger_error('pwg_send_mail function is deprecated', E_USER_NOTICE);
790  }
791 
792  if (!$result)
793  {
794    return pwg_mail($to, array(
795        'content' => $content,
796        'subject' => $subject,
797      ));
798  }
799  else
800  {
801    return $result;
802  }
803}
804
805/**
806 * Moves CSS rules contained in the <style> tag to inline CSS
807 * (for compatibility with Gmail and such clients)
808 * @since 2.6
809 * @param string $content
810 * @return string
811 */
812function move_css_to_body($content)
813{
814  include_once(PHPWG_ROOT_PATH.'include/emogrifier.class.php');
815
816  $e = new Emogrifier($content);
817  // $e->preserveStyleTag = true;
818  return $e->emogrify();
819}
820
821/**
822 * Saves a copy of the mail if _data/tmp
823 * @param boolean $result
824 * @param string $to
825 * @param array $args
826 * @param PHPMailer $mail
827 * @return boolean $result
828 */
829function pwg_send_mail_test($result, $to, $args, $mail)
830{
831  global $conf, $user, $lang_info;
832 
833  $dir = PHPWG_ROOT_PATH.$conf['data_location'].'tmp';
834  if (mkgetdir($dir, MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR))
835  {
836    $filename = $dir.'/mail.'.stripslashes($user['username']).'.'.$lang_info['code'].'.'.$args['theme'].'-'.date('YmdHis');
837    if ($args['content_format'] == 'text/plain')
838    {
839      $filename .= '.txt';
840    }
841    else
842    {
843      $filename .= '.html';
844    }
845   
846    $file = fopen($filename, 'w+');
847    fwrite($file, implode(', ', $to) ."\n");
848    fwrite($file, $mail->Subject ."\n");
849    fwrite($file, $mail->createHeader() ."\n");
850    fwrite($file, $mail->createBody());
851    fclose($file);
852  }
853 
854  return $result;
855}
856
857if ($conf['debug_mail'])
858{
859  add_event_handler('before_send_mail', 'pwg_send_mail_test', EVENT_HANDLER_PRIORITY_NEUTRAL+10, 4);
860}
861
862trigger_action('functions_mail_included');
863
864?>
Note: See TracBrowser for help on using the repository browser.