/** * Send account validation email with a permanent validation link * * @param array user ids to send validation email * @param boolean true if this email is an account activation reminder, false if the account status was changed right now * @return integer the number of successfully sent emails */ function send_easy_validate_emails($user_ids, $is_reminder = true, $email_changed = false) { global $UserSettings, $servertimenow, $secure_htsrv_url; $UserCache =& get_UserCache(); if (isset($GLOBALS['messaging_Module'])) { // Get already received messages for each recepient user $already_received_messages = get_users_unread_threads($user_ids); } $cache_by_locale = array(); $email_sent = 0; foreach ($user_ids as $user_ID) { // Iterate through user ids and send account activation reminder to all user $User = $UserCache->get_by_ID($user_ID, false); if (!$User) { // user not exists continue; } if (!$User->check_status('can_be_validated')) { // User is validated or it is not allowed to be validated continue; } if ($is_reminder && !$UserSettings->get('send_activation_reminder')) { // This is an activation reminder, but user wouldn't like to receive this kind of emails continue; } if (mail_is_blocked($User->get('email'))) { // prevent trying to send an email to a blocked email address continue; } $notify_locale = $User->get('locale'); $reminder_key = $UserSettings->get('last_activation_reminder_key', $User->ID); if (empty($reminder_key) || $email_changed) { // reminder key was not generated yet, or the user email address was changed and we need a new one, to invalidate old requests $reminder_key = generate_random_key(32); $UserSettings->set('last_activation_reminder_key', $reminder_key, $User->ID); } if (!isset($cache_by_locale[$notify_locale])) { // No subject for this locale generated yet: locale_temp_switch($notify_locale); $cache_by_locale[$notify_locale]['subject'] = T_('Activate your account: $login$'); locale_restore_previous(); } $email_template_params = array('locale' => $notify_locale, 'status' => $User->get('status'), 'reminder_key' => $reminder_key, 'is_reminder' => $is_reminder); if (!empty($already_received_messages[$User->ID])) { // add already received message list to email body $email_template_params['already_received_messages'] = $already_received_messages[$User->ID]; } // Update notification sender's info from General settings $User->update_sender(true); if (send_mail_to_User($User->ID, $cache_by_locale[$notify_locale]['subject'], 'account_activate', $email_template_params, true)) { // save corresponding user settings right after the email was sent, to prevent not saving if an eroor occurs $email_sent++; // Set last remind activation email date and increase sent reminder emails number in UserSettings $UserSettings->set('last_activation_email', date2mysql($servertimenow), $User->ID); if ($is_reminder) { $reminder_sent_to_user = $UserSettings->get('activation_reminder_count', $User->ID); $UserSettings->set('activation_reminder_count', $reminder_sent_to_user + 1, $User->ID); } $UserSettings->dbupdate(); } } return $email_sent; }
/** * Send email notification to recipients on new thread or new message event. * * @param boolean true if new thread, false if new message in the current thread * @param boolean the User who sent the message, in case of current User it may be NULL ( This is not the current User e.g. in case of welcome messages ) * @return boolean True if all messages could be sent, false otherwise. */ function send_email_notifications($new_thread = true, $from_User = NULL) { global $DB, $current_User, $admin_url, $baseurl, $app_name; global $Settings, $UserSettings, $servertimenow; // Select recipients of the current thread: $SQL = new SQL(); $SQL->SELECT('u.user_ID, us.uset_value as notify_messages'); $SQL->FROM('T_messaging__threadstatus ts INNER JOIN T_messaging__contact c ON ts.tsta_user_ID = c.mct_to_user_ID AND c.mct_from_user_ID = ' . $this->author_user_ID . ' AND c.mct_blocked = 0 INNER JOIN T_users u ON ts.tsta_user_ID = u.user_ID LEFT OUTER JOIN T_users__usersettings us ON u.user_ID = us.uset_user_ID AND us.uset_name = "notify_messages"'); $SQL->WHERE('ts.tsta_thread_ID = ' . $this->Thread->ID . ' AND ts.tsta_user_ID <> ' . $this->author_user_ID); $thrd_recipients = $DB->get_assoc($SQL->get()); // set message link: list($message_link, $prefs_link) = get_messages_link_to($this->thread_ID); // Construct message subject and body: if ($new_thread) { $subject = NT_('%s just sent you a new message!'); } elseif (count($thrd_recipients) == 1) { $subject = NT_('%s just replied to your message!'); } else { $subject = NT_('%s just replied to a conversation you are involved in!'); } // Get other unread threads $other_unread_threads = get_users_unread_threads(array_keys($thrd_recipients), $this->thread_ID, 'array', 'html'); // Load all users who will be notified $UserCache =& get_UserCache(); $UserCache->load_list(array_keys($thrd_recipients)); // Send email notifications. $ret = true; $def_notify_messages = $Settings->get('def_notify_messages'); foreach ($thrd_recipients as $recipient_ID => $notify_messages) { // Send mail to recipients who needs to be notified. recipients are already loaded into the UserCache if (!($notify_messages || is_null($notify_messages) && $def_notify_messages)) { // User should NOT be notified continue; } $email_template_params = array('recipient_ID' => $recipient_ID, 'new_thread' => $new_thread, 'thrd_recipients' => $thrd_recipients, 'Message' => $this, 'message_link' => $message_link, 'other_unread_threads' => $other_unread_threads[$recipient_ID], 'from_User' => $from_User); $notify_User = $UserCache->get_by_ID($recipient_ID); // Change locale here to localize the email subject and content locale_temp_switch($notify_User->get('locale')); $sender_login = $from_User === NULL ? $current_User->login : $from_User->login; $localized_subject = sprintf(T_($subject), $sender_login); // Note: Not activated users won't get notification email if (send_mail_to_User($recipient_ID, $localized_subject, 'private_message_new', $email_template_params)) { // email sent successful, update las_unread_message_reminder timestamp, because the notification contains all unread messages $UserSettings->set('last_unread_messages_reminder', date2mysql($servertimenow), $recipient_ID); } else { // message was not sent $ret = false; } locale_restore_previous(); } // update reminder timestamp changes $UserSettings->dbupdate(); return $ret; }
} if ($dont_send_reminder || $days_since_reminder < $delay) { // Don't send a new reminder, because the user was not logged in since a very long time or we have already sent a reminder in the last x days ( x = delay value ) unset($users_to_remind_ids[$index]); } } if (empty($users_to_remind_ids)) { // There is no user to remind after we have filtered out those ussers who haven't logged in since a long time $result_message = T_('It was not necessary to send any reminder!'); return 1; } // Set TRUE to use gender settings from back office global $is_admin_page; $is_admin_page = true; // Get all those user threads and their recipients where the corresponding users have unread messages $unread_threads = get_users_unread_threads($users_to_remind_ids, NULL, 'array', 'html'); // Get unread thread urls list($threads_link) = get_messages_link_to(); $reminder_sent = 0; foreach ($users_to_remind_ids as $user_ID) { // send reminder email $email_template_params = array('unread_threads' => $unread_threads[$user_ID], 'threads_link' => $threads_link); $notify_User = $UserCache->get_by_ID($user_ID); // Change locale here to localize the email subject and content locale_temp_switch($notify_User->get('locale')); if (send_mail_to_User($user_ID, T_('You have unread messages!'), 'private_messages_unread_reminder', $email_template_params)) { // Update users last unread message reminder timestamp $UserSettings->set('last_unread_messages_reminder', date2mysql($servertimenow), $user_ID); // save UserSettings after each email, because the cron task mail fail and users won't be updated! $UserSettings->dbupdate(); $reminder_sent++;