source: branches/1.7/include/functions_mail.inc.php @ 4636

Last change on this file since 4636 was 2283, checked in by rub, 16 years ago

Resolved issue 0000815: Email format standardization

  • Property svn:keywords set to Author Date Id Revision
File size: 22.3 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | file          : $Id: functions_mail.inc.php 2283 2008-03-18 21:58:48Z rub $
8// | last update   : $Date: 2008-03-18 21:58:48 +0000 (Tue, 18 Mar 2008) $
9// | last modifier : $Author: rub $
10// | revision      : $Revision: 2283 $
11// +-----------------------------------------------------------------------+
12// | This program is free software; you can redistribute it and/or modify  |
13// | it under the terms of the GNU General Public License as published by  |
14// | the Free Software Foundation                                          |
15// |                                                                       |
16// | This program is distributed in the hope that it will be useful, but   |
17// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
18// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
19// | General Public License for more details.                              |
20// |                                                                       |
21// | You should have received a copy of the GNU General Public License     |
22// | along with this program; if not, write to the Free Software           |
23// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
24// | USA.                                                                  |
25// +-----------------------------------------------------------------------+
26
27// +-----------------------------------------------------------------------+
28// |                               functions                               |
29// +-----------------------------------------------------------------------+
30
31
32/**
33 * Encodes a string using Q form if required (RFC2045)
34 * mail headers MUST contain only US-ASCII characters
35 */
36function encode_mime_header($str)
37{
38  $x = preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
39  if ($x==0)
40  {
41    return $str;
42  }
43  // Replace every high ascii, control =, ? and _ characters
44  $str = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
45                  "'='.sprintf('%02X', ord('\\1'))", $str);
46
47  // Replace every spaces to _ (more readable than =20)
48  $str = str_replace(" ", "_", $str);
49
50  global $lang_info;
51  return '=?'.$lang_info['charset'].'?Q?'.$str.'?=';
52}
53
54/*
55 * Returns the name of the mail sender :
56 *
57 * @return string
58 */
59function get_mail_sender_name()
60{
61  global $conf;
62
63  return (empty($conf['mail_sender_name']) ? $conf['gallery_title'] : $conf['mail_sender_name']);
64}
65
66/*
67 * Returns an array of mail configuration parameters :
68 *
69 * - mail_options: see $conf['mail_options']
70 * - send_bcc_mail_webmaster: see $conf['send_bcc_mail_webmaster']
71 * - email_webmaster: mail corresponding to $conf['webmaster_id']
72 * - formated_email_webmaster: the name of webmaster is $conf['gallery_title']
73 * - text_footer: PhpWebGallery and version
74 *
75 * @return array
76 */
77function get_mail_configuration()
78{
79  global $conf;
80
81  $conf_mail = array(
82    'mail_options' => $conf['mail_options'],
83    'send_bcc_mail_webmaster' => $conf['send_bcc_mail_webmaster'],
84    'default_email_format' => $conf['default_email_format'],
85    'use_smtp' => !empty($conf['smtp_host']),
86    'smtp_host' => $conf['smtp_host'],
87    'smtp_user' => $conf['smtp_user'],
88    'smtp_password' => $conf['smtp_password']
89    );
90
91  // we have webmaster id among user list, what's his email address ?
92  $conf_mail['email_webmaster'] = get_webmaster_mail_address();
93
94  // name of the webmaster is the title of the gallery
95  $conf_mail['formated_email_webmaster'] =
96    format_email(get_mail_sender_name(), $conf_mail['email_webmaster']);
97
98  $conf_mail['boundary_key'] = generate_key(32);
99
100  return $conf_mail;
101}
102
103/**
104 * Returns an email address with an associated real name
105 *
106 * @param string name
107 * @param string email
108 */
109function format_email($name, $email)
110{
111  // Spring cleaning
112  $cvt_email = trim(preg_replace('#[\n\r]+#s', '', $email));
113  $cvt_name = trim(preg_replace('#[\n\r]+#s', '', $name));
114
115  if ($cvt_name!="")
116  {
117    $cvt_name = encode_mime_header(
118              '"'
119              .addcslashes($cvt_name,'"')
120              .'"');
121    $cvt_name .= ' ';
122  }
123
124  if (strpos($cvt_email, '<') === false)
125  {
126    return $cvt_name.'<'.$cvt_email.'>';
127  }
128  else
129  {
130    return $cvt_name.$cvt_email;
131  }
132}
133
134/**
135 * Returns an email address list with minimal email string
136 *
137 * @param string with email list (email separated by comma)
138 */
139function get_strict_email_list($email_list)
140{
141  $result = array();
142  $list = explode(',', $email_list);
143  foreach ($list as $email)
144  {
145    if (strpos($email, '<') !== false)
146    {
147       $email = preg_replace('/.*<(.*)>.*/i', '$1', $email);
148    }
149    $result[] = trim($email);
150  }
151
152  return implode(',', $result);
153}
154
155/**
156 * Returns an completed array template/theme
157 * completed with get_default_template()
158 *
159 * @params:
160 *   - args: incompleted array of template/theme
161 *       o template: template to use [default get_default_template()]
162 *       o theme: template to use [default get_default_template()]
163 */
164function get_array_template_theme($args = array())
165{
166  global $conf;
167
168  $res = array();
169
170  if (empty($args['template']) or empty($args['theme']))
171  {
172    list($res['template'], $res['theme']) = explode('/', get_default_template());
173  }
174
175  if (!empty($args['template']))
176  {
177    $res['template'] = $args['template'];
178  }
179
180  if (!empty($args['theme']))
181  {
182    $res['theme'] = $args['theme'];
183  }
184
185  return $res;
186}
187
188/**
189 * Return an new mail template
190 *
191 * @params:
192 *   - email_format: mail format
193 *   - args: function params of mail function:
194 *       o template: template to use [default get_default_template()]
195 *       o theme: template to use [default get_default_template()]
196 */
197function get_mail_template($email_format, $args = array())
198{
199  $args = get_array_template_theme($args);
200
201  $mail_template = new Template(PHPWG_ROOT_PATH.'template/'.$args['template'], $args['theme']);
202  $mail_template->set_rootdir(PHPWG_ROOT_PATH.'template/'.$args['template'].'/mail/'.$email_format);
203
204  return $mail_template;
205}
206
207/**
208 * Return string email format (html or not)
209 *
210 * @param string format
211 */
212function get_str_email_format($is_html)
213{
214  return ($is_html ? 'text/html' : 'text/plain');
215}
216
217/*
218 * Switch language to param language
219 * All entries are push on language stack
220 *
221 * @param string language
222 */
223function switch_lang_to($language)
224{
225  global $switch_lang, $user, $lang, $lang_info;
226
227  if (count($switch_lang['stack']) == 0)
228  {
229    $prev_language = $user['language'];
230  }
231  else
232  {
233    $prev_language = end($switch_lang['stack']);
234  }
235
236  $switch_lang['stack'][] = $language;
237
238  if ($prev_language != $language)
239  {
240    if (!isset($switch_lang['language'][$prev_language]))
241    {
242      $switch_lang[$prev_language]['lang_info'] = $lang_info;
243      $switch_lang[$prev_language]['lang'] = $lang;
244    }
245
246    if (!isset($switch_lang['language'][$language]))
247    {
248      // Re-Init language arrays
249      $lang_info = array();
250      $lang  = array();
251
252      // language files
253      include(get_language_filepath('common.lang.php', '', $language));
254      // No test admin because script is checked admin (user selected no)
255      // Translations are in admin file too
256      include(get_language_filepath('admin.lang.php', '', $language));
257      trigger_action('loading_lang');
258      @include(get_language_filepath('local.lang.php', '', $language));
259
260      $switch_lang[$language]['lang_info'] = $lang_info;
261      $switch_lang[$language]['lang'] = $lang;
262    }
263    else
264    {
265      $lang_info = $switch_lang[$language]['lang_info'];
266      $lang = $switch_lang[$language]['lang'];
267    }
268
269    $user['language'] = $language;
270  }
271}
272
273/*
274 * Switch back language pushed with switch_lang_to function
275 *
276 * @param: none
277 */
278function switch_lang_back()
279{
280  global $switch_lang, $user, $lang, $lang_info;
281
282  $last_language = array_pop($switch_lang['stack']);
283
284  if (count($switch_lang['stack']) > 0)
285  {
286    $language = end($switch_lang['stack']);
287  }
288  else
289  {
290    $language = $user['language'];
291  }
292
293  if ($last_language != $language)
294  {
295    if (!isset($switch_lang['language'][$language]))
296    {
297      $lang_info = $switch_lang[$language]['lang_info'];
298      $lang = $switch_lang[$language]['lang'];
299    }
300    $user['language'] = $language;
301  }
302}
303
304/**
305 * Returns email of all administrator
306 *
307 * @return string
308 */
309/*
310 * send en notification email to all administrators
311 * if a administrator is doing action,
312 * he's be removed to email list
313 *
314 * @param:
315 *   - keyargs_subject: mail subject on l10n_args format
316 *   - keyargs_content: mail content on l10n_args format
317 *
318 * @return boolean (Ok or not)
319 */
320function pwg_mail_notification_admins($keyargs_subject, $keyargs_content)
321{
322  // Check arguments
323  if 
324    (
325      empty($keyargs_subject) or
326      empty($keyargs_content)
327    )
328  {
329    return false;
330  }
331
332  global $conf, $user;
333  $return = true;
334
335  $admins = array();
336
337  $query = '
338select
339  U.'.$conf['user_fields']['username'].' as username,
340  U.'.$conf['user_fields']['email'].' as mail_address
341from
342  '.USERS_TABLE.' as U,
343  '.USER_INFOS_TABLE.' as I
344where
345  I.user_id =  U.'.$conf['user_fields']['id'].' and
346  I.status in (\'webmaster\',  \'admin\') and
347  I.adviser = \'false\' and
348  '.$conf['user_fields']['email'].' is not null and
349  I.user_id <> '.$user['id'].'
350order by
351  username
352';
353
354  $datas = pwg_query($query);
355  if (!empty($datas))
356  {
357    while ($admin = mysql_fetch_array($datas))
358    {
359      if (!empty($admin['mail_address']))
360      {
361        array_push($admins, format_email($admin['username'], $admin['mail_address']));
362      }
363    }
364  }
365
366  if (count($admins) > 0)
367  {
368    $keyargs_content_admin_info = array
369    (
370      get_l10n_args('Connected user: %s', $user['username']),
371      get_l10n_args('IP: %s', $_SERVER['REMOTE_ADDR']),
372      get_l10n_args('Browser: %s', $_SERVER['HTTP_USER_AGENT'])
373    );
374
375    switch_lang_to(get_default_language());
376
377    $return = pwg_mail
378    (
379      '',
380      array
381      (
382        'Bcc' => $admins,
383        'subject' => '['.$conf['gallery_title'].'] '.l10n_args($keyargs_subject),
384        'content' =>
385           l10n_args($keyargs_content)."\n\n"
386          .l10n_args($keyargs_content_admin_info)."\n",
387        'content_format' => 'text/plain'
388      )
389    ) and $return;
390
391    switch_lang_back();
392  }
393
394  return $return;
395}
396
397/*
398 * send en email to user's group
399 *
400 * @param:
401 *   - group_id: mail are sent to group with this Id
402 *   - email_format: mail format
403 *   - keyargs_subject: mail subject on l10n_args format
404 *   - dirname: short name of directory including template
405 *   - tpl_shortname: short template name without extension
406 *   - assign_vars: array used to assign_vars to mail template
407 *   - language_selected: send mail only to user with this selected language
408 *
409 * @return boolean (Ok or not)
410 */
411function pwg_mail_group(
412  $group_id, $email_format, $keyargs_subject,
413  $dirname, $tpl_shortname,
414  $assign_vars = array(), $language_selected = '')
415{
416  // Check arguments
417  if 
418    (
419      empty($group_id) or
420      empty($email_format) or
421      empty($keyargs_subject) or
422      empty($tpl_shortname)
423    )
424  {
425    return false;
426  }
427
428  global $conf;
429  $return = true;
430
431  $query = '
432SELECT
433  distinct language, template
434FROM
435  '.USER_GROUP_TABLE.' as ug
436  INNER JOIN '.USERS_TABLE.' as u  ON '.$conf['user_fields']['id'].' = ug.user_id
437  INNER JOIN '.USER_INFOS_TABLE.' as ui  ON ui.user_id = ug.user_id
438WHERE
439        '.$conf['user_fields']['email'].' IS NOT NULL
440    AND group_id = '.$group_id;
441
442  if (!empty($language_selected))
443  {
444    $query .= '
445    AND language = \''.$language_selected.'\'';
446  }
447
448    $query .= '
449;';
450
451  $result = pwg_query($query);
452
453  if (mysql_num_rows($result) > 0)
454  {
455    $list = array();
456    while ($row = mysql_fetch_array($result))
457    {
458      $row['template_theme'] = $row['template'];
459      list($row['template'], $row['theme']) = explode('/', $row['template_theme']);
460      $list[] = $row;
461    }
462
463    foreach ($list as $elem)
464    {
465      $query = '
466SELECT
467  u.'.$conf['user_fields']['username'].' as username,
468  u.'.$conf['user_fields']['email'].' as mail_address
469FROM
470  '.USER_GROUP_TABLE.' as ug
471  INNER JOIN '.USERS_TABLE.' as u  ON '.$conf['user_fields']['id'].' = ug.user_id
472  INNER JOIN '.USER_INFOS_TABLE.' as ui  ON ui.user_id = ug.user_id
473WHERE
474        '.$conf['user_fields']['email'].' IS NOT NULL
475    AND group_id = '.$group_id.'
476    AND language = \''.$elem['language'].'\'
477    AND template = \''.$elem['template_theme'].'\'
478;';
479
480      $result = pwg_query($query);
481
482      if (mysql_num_rows($result) > 0)
483      {
484        $Bcc = array();
485        while ($row = mysql_fetch_array($result))
486        {
487          if (!empty($row['mail_address']))
488          {
489            array_push($Bcc, format_email($row['username'], $row['mail_address']));
490          }
491        }
492
493        if (count($Bcc) > 0)
494        {
495          switch_lang_to($elem['language']);
496
497          $mail_template = get_mail_template($email_format, $elem);
498          $mail_template->set_filename($tpl_shortname,
499            (empty($dirname) ? '' : $dirname.'/').$tpl_shortname.'.tpl');
500
501          $mail_template->assign_vars(
502            trigger_event('mail_group_assign_vars', $assign_vars));
503
504          $return = pwg_mail
505          (
506            '',
507            array
508            (
509              'Bcc' => $Bcc,
510              'subject' => l10n_args($keyargs_subject),
511              'email_format' => $email_format,
512              'content' => $mail_template->parse($tpl_shortname, true),
513              'content_format' => $email_format,
514              'template' => $elem['template'],
515              'theme' => $elem['theme']
516            )
517          ) and $return;
518
519          switch_lang_back();
520        }
521      }
522    }
523  }
524
525  return $return;
526}
527
528/*
529 * sends an email, using PhpWebGallery specific informations
530 *
531 * @param:
532 *   - to: receiver(s) of the mail (list separated by comma).
533 *   - args: function params of mail function:
534 *       o from: sender [default value webmaster email]
535 *       o Cc: array of carbon copy receivers of the mail. [default value empty]
536 *       o Bcc: array of blind carbon copy receivers of the mail. [default value empty]
537 *       o subject  [default value 'PhpWebGallery']
538 *       o content: content of mail    [default value '']
539 *       o content_format: format of mail content  [default value 'text/plain']
540 *       o email_format: global mail format  [default value $conf_mail['default_email_format']]
541 *       o template: template to use [default get_default_template()]
542 *       o theme: template to use [default get_default_template()]
543 *
544 * @return boolean (Ok or not)
545 */
546function pwg_mail($to, $args = array())
547{
548  global $conf, $conf_mail, $lang_info, $page;
549
550  if (empty($to) and empty($args['Cc']) and empty($args['Bcc']))
551  {
552    return true;
553  }
554
555  if (!isset($conf_mail))
556  {
557    $conf_mail = get_mail_configuration();
558  }
559
560  if (empty($args['email_format']))
561  {
562    $args['email_format'] = $conf_mail['default_email_format'];
563  }
564
565  // Compute root_path in order have complete path
566  if ($args['email_format'] == 'text/html')
567  {
568    set_make_full_url();
569  }
570
571  if (empty($args['from']))
572  {
573    $args['from'] = $conf_mail['formated_email_webmaster'];
574  }
575  else
576  {
577    $args['from'] = format_email('', $args['from']);
578  }
579
580  if (empty($args['subject']))
581  {
582    $args['subject'] = 'PhpWebGallery';
583  }
584  // Spring cleaning
585  $cvt_subject = trim(preg_replace('#[\n\r]+#s', '', $args['subject']));
586  // Ascii convertion
587  $cvt_subject = encode_mime_header($cvt_subject);
588
589  if (!isset($args['content']))
590  {
591    $args['content'] = '';
592  }
593
594  if (empty($args['content_format']))
595  {
596    $args['content_format'] = 'text/plain';
597  }
598
599  if ($conf_mail['send_bcc_mail_webmaster'])
600  {
601    $args['Bcc'][] = $conf_mail['formated_email_webmaster'];
602  }
603
604  if (($args['content_format'] == 'text/html') and ($args['email_format'] == 'text/plain'))
605  {
606    // Todo find function to convert html text to plain text
607    return false;
608  }
609
610  $args = array_merge($args, get_array_template_theme($args));
611
612  $headers = 'From: '.$args['from']."\n";
613  $headers.= 'Reply-To: '.$args['from']."\n";
614  if (empty($to))
615  {
616    $headers.= 'To: undisclosed-recipients: ;'."\n";
617  }
618  else
619  {
620    $headers.= 'To: '.$to."\n";
621  }
622
623  if (!empty($args['Cc']))
624  {
625    $headers.= 'Cc: '.implode(',', $args['Cc'])."\n";
626  }
627
628  if (!empty($args['Bcc']))
629  {
630    $headers.= 'Bcc: '.implode(',', $args['Bcc'])."\n";
631  }
632
633  $headers.= 'Content-Type: multipart/alternative;'."\n";
634  $headers.= '  boundary="---='.$conf_mail['boundary_key'].'";'."\n";
635  $headers.= '  reply-type=original'."\n";
636  $headers.= 'MIME-Version: 1.0'."\n";
637  $headers.= 'X-Mailer: Piwigo Mailer'."\n";
638
639  $content = '';
640
641  if (!isset($conf_mail[$args['email_format']][$lang_info['code']][$lang_info['charset']][$args['template']][$args['theme']]))
642  {
643    if (!isset($mail_template))
644    {
645      $mail_template = get_mail_template($args['email_format']);
646    }
647
648    $mail_template->set_filename('mail_header', 'header.tpl');
649    $mail_template->set_filename('mail_footer', 'footer.tpl');
650
651    $mail_template->assign_vars(
652      array(
653        //Header
654        'BOUNDARY_KEY' => $conf_mail['boundary_key'],
655        'CONTENT_TYPE' => $args['email_format'],
656        'CONTENT_ENCODING' => $lang_info['charset'],
657        'LANG' => $lang_info['code'],
658        'DIR' => $lang_info['direction'],
659
660        // Footer
661        'GALLERY_URL' =>
662          isset($page['gallery_url']) ?
663                $page['gallery_url'] : $conf['gallery_url'],
664        'GALLERY_TITLE' =>
665          isset($page['gallery_title']) ?
666                $page['gallery_title'] : $conf['gallery_title'],
667        'VERSION' => $conf['show_version'] ? PHPWG_VERSION : '',
668        'PHPWG_URL' => PHPWG_URL,
669
670        'TITLE_MAIL' => urlencode(l10n('title_send_mail')),
671        'MAIL' => get_webmaster_mail_address()
672        ));
673
674    if ($args['email_format'] == 'text/html')
675    {
676      $old_root = $mail_template->root;
677
678      if (is_file($mail_template->root.'/global-mail-css.tpl'))
679      {
680        $mail_template->set_filename('global_mail_css', 'global-mail-css.tpl');
681        $mail_template->assign_var_from_handle('GLOBAL_MAIL_CSS', 'global_mail_css');
682      }
683
684      $mail_template->root = PHPWG_ROOT_PATH.'template/'.$args['template'].'/theme/'.$args['theme'];
685      if (is_file($mail_template->root.'/mail-css.tpl'))
686      {
687        $mail_template->set_filename('mail_css', 'mail-css.tpl');
688        $mail_template->assign_var_from_handle('MAIL_CSS', 'mail_css');
689      }
690
691      $mail_template->root = PHPWG_ROOT_PATH.'template-common';
692      if (is_file($mail_template->root.'/local-mail-css.tpl'))
693      {
694        $mail_template->set_filename('local_mail_css', 'local-mail-css.tpl');
695        $mail_template->assign_var_from_handle('LOCAL_MAIL_CSS', 'local_mail_css');
696      }
697
698      $mail_template->root = $old_root;
699    }
700
701    // what are displayed on the header of each mail ?
702    $conf_mail[$args['email_format']]
703      [$lang_info['code']][$lang_info['charset']]
704      [$args['template']][$args['theme']]['header'] =
705        $mail_template->parse('mail_header', true);
706
707    // what are displayed on the footer of each mail ?
708    $conf_mail[$args['email_format']]
709      [$lang_info['code']][$lang_info['charset']]
710      [$args['template']][$args['theme']]['footer'] =
711        $mail_template->parse('mail_footer', true);
712  }
713
714  // Header
715  $content.= $conf_mail[$args['email_format']]
716              [$lang_info['code']][$lang_info['charset']]
717              [$args['template']][$args['theme']]['header'];
718
719  // Content
720  if (($args['content_format'] == 'text/plain') and ($args['email_format'] == 'text/html'))
721  {
722    $content.= '<p>'.
723                nl2br(
724                  preg_replace("/(http:\/\/)([^\s,]*)/i",
725                               "<a href='$1$2'>$1$2</a>",
726                               htmlentities($args['content']))).
727                '</p>';
728  }
729  else
730  {
731    $content.= $args['content'];
732  }
733
734  // Footer
735  $content.= $conf_mail[$args['email_format']]
736              [$lang_info['code']][$lang_info['charset']]
737              [$args['template']][$args['theme']]['footer'];
738
739  // Close boundary
740  $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n";
741
742   // Undo Compute root_path in order have complete path
743  if ($args['email_format'] == 'text/html')
744  {
745    unset_make_full_url();
746  }
747
748  return
749    trigger_event('send_mail',
750      false, /* Result */
751      trigger_event('send_mail_to', get_strict_email_list($to)),
752      trigger_event('send_mail_subject', $cvt_subject),
753      trigger_event('send_mail_content', $content),
754      trigger_event('send_mail_headers', $headers),
755      $args
756    );
757}
758
759/*
760 * pwg sendmail
761 *
762 * @param:
763 *   - result of other sendmail
764 *   - to: Receiver or receiver(s) of the mail.
765 *   - subject  [default value 'PhpWebGallery']
766 *   - content: content of mail
767 *   - headers: headers of mail
768 *
769 * @return boolean (Ok or not)
770 */
771function pwg_send_mail($result, $to, $subject, $content, $headers)
772{
773  if (!$result)
774  {
775    global $conf_mail;
776
777    if ($conf_mail['use_smtp'])
778    {
779      include_once( PHPWG_ROOT_PATH.'include/class_smtp_mail.inc.php' );
780      $smtp_mail = new smtp_mail(
781        $conf_mail['smtp_host'], $conf_mail['smtp_user'], $conf_mail['smtp_password'],
782        $conf_mail['email_webmaster']);
783      return $smtp_mail->mail($to, $subject, $content, $headers);
784    }
785    else
786    {
787      if ($conf_mail['mail_options'])
788      {
789        $options = '-f '.$conf_mail['email_webmaster'];
790        return mail($to, $subject, $content, $headers, $options);
791      }
792      else
793      {
794        return mail($to, $subject, $content, $headers);
795      }
796    }
797  }
798  else
799  {
800    return $result;
801  }
802}
803
804/*Testing block
805function pwg_send_mail_test($result, $to, $subject, $content, $headers, $args)
806{
807    global $user, $lang_info;
808    @mkdir(PHPWG_ROOT_PATH.'testmail');
809    $filename = PHPWG_ROOT_PATH.'testmail/mail.'.$user['username'].'.'.$lang_info['code'].'.'.$args['template'].'.'.$args['theme'];
810    if ($args['content_format'] == 'text/plain')
811    {
812      $filename .= '.txt';
813    }
814    else
815    {
816      $filename .= '.html';
817    }
818    $file = fopen($filename, 'w+');
819    fwrite($file, $to);
820    fwrite($file, $subject);
821    fwrite($file, $headers);
822    fwrite($file, $content);
823    fclose($file);
824    return true;
825}
826add_event_handler('send_mail', 'pwg_send_mail_test', 0, 6);*/
827
828
829add_event_handler('send_mail', 'pwg_send_mail', EVENT_HANDLER_PRIORITY_NEUTRAL, 5);
830trigger_action('functions_mail_included');
831
832?>
Note: See TracBrowser for help on using the repository browser.