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

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

Resolved issue 0000812: Format error with "$confenabled_format_email = false;"

Merge branch-1_7 2278:2279 into BSF

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