Example #1
0
 /**
  * Send a mail to the user list
  *
  * @param int $userIdList list of the user
  * @param string $message body of the mail
  * @param string $subject subject of the mail
  * @param string $specificFrom email of the sender
  * @param string $specificFromName name to display
  * @param string $altBody link of the message in case of problem of read
  * 
  */
 protected static function emailNotification($userIdList, $message, $subject, $specificFrom = '', $specificFromName = '', $altBody = '')
 {
     if (!is_array($userIdList)) {
         $userIdList = array($userIdList);
     }
     if (count($userIdList) == 0) {
         return 0;
     }
     $tbl = claro_sql_get_main_tbl();
     $tbl_user = $tbl['user'];
     $sql = 'SELECT DISTINCT email
             FROM `' . $tbl_user . '`
             WHERE user_id IN (' . implode(', ', array_map('intval', $userIdList)) . ')';
     $emailList = claro_sql_query_fetch_all_cols($sql);
     $emailList = $emailList['email'];
     $emailList = array_filter($emailList, 'is_well_formed_email_address');
     $mail = new ClaroPHPMailer();
     $mail->IsHTML(true);
     if (!empty($altBody)) {
         $mail->AltBody = $altBody;
     }
     if ($specificFrom != '') {
         $mail->From = $specificFrom;
     } else {
         $mail->From = get_conf('administrator_email');
     }
     if ($specificFromName != '') {
         $mail->FromName = $specificFromName;
     } else {
         $mail->FromName = get_conf('administrator_name');
     }
     $mail->Sender = $mail->From;
     if (strlen($subject) > 78) {
         $message = get_lang('Subject') . ' : ' . $subject . "<br />\n\n" . $message;
         $subject = substr($subject, 0, 73) . '...';
     }
     $mail->Subject = $subject;
     $mail->Body = $message;
     if (claro_debug_mode()) {
         $message = '<p>' . get_lang('Subject') . ' : ' . claro_htmlspecialchars($subject) . '</p>' . "\n" . '<p>' . get_lang('Message') . ' : <pre>' . claro_htmlspecialchars($message) . '</pre></p>' . "\n" . '<p>' . get_lang('Sender') . ' : ' . claro_htmlspecialchars($mail->FromName) . ' - ' . claro_htmlspecialchars($mail->From) . '</p>' . "\n" . '<p>' . get_lang('Recipient') . ' : ' . implode(', ', $emailList) . '</p>' . "\n";
         pushClaroMessage($message, 'mail');
     }
     $error_list = array();
     foreach ($emailList as $thisEmail) {
         try {
             $mail->AddAddress($thisEmail);
             $mail->Send();
         } catch (phpmailerException $exception) {
             if (claro_debug_mode()) {
                 pushClaroMessage('Mail Notification Failed ' . $exception->__toString());
                 $error_list[] = $thisEmail;
             }
         }
         $mail->ClearAddresses();
     }
 }