From 92fc9abb14a2186806ed50322730caae54909f0f Mon Sep 17 00:00:00 2001 From: rub Date: Thu, 7 Dec 2006 23:49:52 +0000 Subject: Feature Issue ID 0000598: Possibility to send HTML mail git-svn-id: http://piwigo.org/svn/trunk@1642 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/config_default.inc.php | 5 +++ include/functions_mail.inc.php | 77 ++++++++++++++++++++++++++++++++++---- template/yoga/mail/admin/index.php | 35 +++++++++++++++++ template/yoga/mail/footer.tpl | 16 ++++++++ template/yoga/mail/header.tpl | 10 +++++ template/yoga/mail/index.php | 35 +++++++++++++++++ 6 files changed, 170 insertions(+), 8 deletions(-) create mode 100644 template/yoga/mail/admin/index.php create mode 100644 template/yoga/mail/footer.tpl create mode 100644 template/yoga/mail/header.tpl create mode 100644 template/yoga/mail/index.php diff --git a/include/config_default.inc.php b/include/config_default.inc.php index 78d443636..1f572fe91 100644 --- a/include/config_default.inc.php +++ b/include/config_default.inc.php @@ -224,6 +224,11 @@ $conf['send_bcc_mail_webmaster'] = false; // There are webhosting wich not allow email formatted (Lycos, ...) $conf['enabled_format_email'] = true; +// default_email_format: +// Define the default email format use to send email +// Value could be text/plain or text/html +$conf['default_email_format'] = 'text/plain'; + // check_upgrade_feed: check if there are database upgrade required. Set to // true, a message will strongly encourage you to upgrade your database if // needed. diff --git a/include/functions_mail.inc.php b/include/functions_mail.inc.php index 5e0ed25e6..146e06bb1 100644 --- a/include/functions_mail.inc.php +++ b/include/functions_mail.inc.php @@ -53,7 +53,8 @@ function get_mail_configuration() $conf_mail = array( 'mail_options' => $conf['mail_options'], - 'send_bcc_mail_webmaster' => $conf['send_bcc_mail_webmaster'], + 'send_bcc_mail_webmaster' => $conf['send_bcc_mail_webmaster'], + 'default_email_format' => $conf['default_email_format'] ); // we have webmaster id among user list, what's his email address ? @@ -101,10 +102,10 @@ function format_email($name, $email) /** * sends an email, using PhpWebGallery specific informations - */ -function pwg_mail($to, $from = '', $subject = 'PhpWebGallery', $infos = '') + */ +function pwg_mail($to, $from = '', $subject = 'PhpWebGallery', $infos = '', $format_infos = 'text/plain', $email_format = null) { - global $conf, $conf_mail, $lang_info; + global $conf, $conf_mail, $lang_info, $user; $cvt7b_subject = str_translate_to_ascii7bits($subject); @@ -112,6 +113,17 @@ function pwg_mail($to, $from = '', $subject = 'PhpWebGallery', $infos = '') { $conf_mail = get_mail_configuration(); } + + if (is_null($email_format)) + { + $email_format = $conf_mail['default_email_format']; + } + + if (($format_infos == 'text/html') and ($email_format == 'text/plain')) + { + // Todo find function to convert html text to plain text + return false; + } $to = format_email('', $to); @@ -126,16 +138,65 @@ function pwg_mail($to, $from = '', $subject = 'PhpWebGallery', $infos = '') $headers = 'From: '.$from."\n"; $headers.= 'Reply-To: '.$from."\n"; - $headers.= 'Content-Type: text/plain;format=flowed;charset="'.$lang_info['charset'].'";'; + $headers.= 'Content-Type: '.$email_format.';format=flowed;charset="'.$lang_info['charset'].'";'; $headers.= 'reply-type=original'."\n"; if ($conf_mail['send_bcc_mail_webmaster']) { $headers.= 'Bcc: '.$conf_mail['formated_email_webmaster']."\n"; } - - $content = $infos; - $content.= $conf_mail['text_footer']; + + list($tmpl, $thm) = explode('/', $conf['default_template']); + $template_mail = new Template(PHPWG_ROOT_PATH.'template/'.$tmpl, $thm); + + $content = ''; + + if ($email_format == 'text/html') + { + $template_mail->set_filenames(array('mail_header'=>'mail/header.tpl')); + + $template_mail->assign_vars( + array( + 'BODY_ID' => + isset($page['body_id']) ? + $page['body_id'] : '', + + 'CONTENT_ENCODING' => $lang_info['charset'], + 'LANG'=>$lang_info['code'], + 'DIR'=>$lang_info['direction'] + + )); + + $content.= $template_mail->parse('mail_header', true); + } + + if (($format_infos == 'text/plain') and ($email_format == 'text/html')) + { + $content.= '
'.htmlentities($infos).'
'; + } + else + { + $content.= $infos; + } + + if ($email_format == 'text/plain') + { + $content.= $conf_mail['text_footer']; + } + else + { + $template_mail->set_filenames(array('mail_footer'=>'footer.tpl')); + + $template_mail->assign_vars( + array( + 'VERSION' => $conf['show_version'] ? PHPWG_VERSION : '', + + 'L_TITLE_MAIL' => urlencode(l10n('title_send_mail')), + 'MAIL' => get_webmaster_mail_address() + )); + + $content.= $template_mail->parse('mail_footer', true); + } if ($conf_mail['mail_options']) { diff --git a/template/yoga/mail/admin/index.php b/template/yoga/mail/admin/index.php new file mode 100644 index 000000000..ad16c4524 --- /dev/null +++ b/template/yoga/mail/admin/index.php @@ -0,0 +1,35 @@ + diff --git a/template/yoga/mail/footer.tpl b/template/yoga/mail/footer.tpl new file mode 100644 index 000000000..1110dacdf --- /dev/null +++ b/template/yoga/mail/footer.tpl @@ -0,0 +1,16 @@ + + + + + diff --git a/template/yoga/mail/header.tpl b/template/yoga/mail/header.tpl new file mode 100644 index 000000000..fee4d441c --- /dev/null +++ b/template/yoga/mail/header.tpl @@ -0,0 +1,10 @@ + + + + + + + +
+ diff --git a/template/yoga/mail/index.php b/template/yoga/mail/index.php new file mode 100644 index 000000000..ad16c4524 --- /dev/null +++ b/template/yoga/mail/index.php @@ -0,0 +1,35 @@ + -- cgit v1.2.3