/** * Sends an email to User * * @param integer Recipient ID. * @param string Subject of the mail * @param string Email template name * @param array Email template params * @param boolean Force to send this email even if the user is not activated. By default not activated user won't get emails. * Pasword reset, and account activation emails must be always forced. * @param array Additional headers ( headername => value ). Take care of injection! * @return boolean True if mail could be sent (not necessarily delivered!), false if not - (return value of {@link mail()}) */ function send_mail_to_User($user_ID, $subject, $template_name, $template_params = array(), $force_on_non_activated = false, $headers = array()) { global $UserSettings, $Settings, $current_charset; $UserCache =& get_UserCache(); if ($User = $UserCache->get_by_ID($user_ID)) { if (!$User->check_status('can_receive_any_message')) { // user status doesn't allow to receive nor emails nor private messages return false; } if (!($User->check_status('is_validated') || $force_on_non_activated)) { // user is not activated and non activated users should not receive emails, unless force_on_non_activated is turned on return false; } // UserSettings update is not required yet $update_settings = false; // Check if a new email to User with the corrensponding email type is allowed switch ($template_name) { case 'account_activate': if ($Settings->get('validation_process') == 'easy' && !$template_params['is_reminder']) { // this is not a notification email break; } case 'private_message_new': case 'private_messages_unread_reminder': case 'post_new': case 'comment_new': case 'account_activated': case 'account_closed': case 'account_reported': // this is a notificaiton email if (!check_allow_new_email('notification_email_limit', 'last_notification_email', $User->ID)) { // more notification email is not allowed today return false; } $update_settings = true; break; case 'newsletter': // this is a newsletter email if (!check_allow_new_email('newsletter_limit', 'last_newsletter', $User->ID)) { // more newsletter email is not allowed today return false; } $update_settings = true; break; } // Update notification sender's info from General settings $User->update_sender(); switch ($UserSettings->get('email_format', $User->ID)) { // Set Content-Type from user's setting "Email format" case 'auto': $template_params['boundary'] = 'b2evo-' . md5(rand()); $headers['Content-Type'] = 'multipart/mixed; boundary="' . $template_params['boundary'] . '"'; break; case 'html': $headers['Content-Type'] = 'text/html; charset=' . $current_charset; break; case 'text': $headers['Content-Type'] = 'text/plain; charset=' . $current_charset; break; } // Get a message text from template file $message = mail_template($template_name, $UserSettings->get('email_format', $User->ID), $template_params, $User); // Autoinsert user's data $subject = mail_autoinsert_user_data($subject, $User); $message = mail_autoinsert_user_data($message, $User); if (send_mail($User->email, NULL, $subject, $message, NULL, NULL, $headers, $user_ID)) { // email was sent, update last email settings; if ($update_settings) { // User Settings need to be updated $UserSettings->dbupdate(); } return true; } } // No user or email could not be sent return false; }
} $AdminUI->breadcrumbpath_init(false); // fp> I'm playing with the idea of keeping the current blog in the path here... $AdminUI->breadcrumbpath_add(T_('Users'), '?ctrl=users'); $AdminUI->breadcrumbpath_add(T_('List'), '?ctrl=users'); $AdminUI->breadcrumbpath_add(T_('Newsletter'), '?ctrl=newsletter'); $AdminUI->set_path('users', 'users'); // Display <html><head>...</head> section! (Note: should be done early if actions do not redirect) $AdminUI->disp_html_head(); // Display title, menu, messages, etc. (Note: messages MUST be displayed AFTER the actions) $AdminUI->disp_body_top(); $AdminUI->disp_payload_begin(); /* * Display appropriate payload: */ switch ($action) { case 'preview': $email_newsletter_params = array('message' => $Session->get('newsletter_message')); $newsletter = array('title' => mail_autoinsert_user_data($Session->get('newsletter_title'), $current_User), 'html' => mail_autoinsert_user_data(mail_template('newsletter', 'html', $email_newsletter_params, $current_User), $current_User), 'text' => mail_autoinsert_user_data(mail_template('newsletter', 'text', $email_newsletter_params, $current_User), $current_User)); $AdminUI->disp_view('newsletter/views/_newsletter_preview.view.php'); break; case 'send': $AdminUI->disp_view('newsletter/views/_newsletter_report.view.php'); break; default: $AdminUI->disp_view('newsletter/views/_newsletter.form.php'); break; } $AdminUI->disp_payload_end(); // Display body bottom, debug info and close </html>: $AdminUI->disp_global_footer();