Exemplo n.º 1
0
 /**
  * @param  JMail  $mail
  * @param  array  $receivers
  *
  * @return boolean
  */
 public static function send(JMail $mail, array $receivers)
 {
     $config = KunenaFactory::getConfig();
     if (!empty($config->email_recipient_count)) {
         $email_recipient_count = $config->email_recipient_count;
     } else {
         $email_recipient_count = 1;
     }
     $email_recipient_privacy = $config->get('email_recipient_privacy', 'bcc');
     // If we hide email addresses from other users, we need to add TO address to prevent email from becoming spam.
     if ($email_recipient_count > 1 && $email_recipient_privacy == 'bcc' && JMailHelper::isEmailAddress($config->get('email_visible_address'))) {
         $mail->AddAddress($config->email_visible_address, JMailHelper::cleanAddress($config->board_title));
         // Also make sure that email receiver limits are not violated (TO + CC + BCC = limit).
         if ($email_recipient_count > 9) {
             $email_recipient_count--;
         }
     }
     $chunks = array_chunk($receivers, $email_recipient_count);
     $success = true;
     foreach ($chunks as $emails) {
         if ($email_recipient_count == 1 || $email_recipient_privacy == 'to') {
             echo 'TO ';
             $mail->ClearAddresses();
             $mail->addRecipient($emails);
         } elseif ($email_recipient_privacy == 'cc') {
             echo 'CC ';
             $mail->ClearCCs();
             $mail->addCC($emails);
         } else {
             echo 'BCC ';
             $mail->ClearBCCs();
             $mail->addBCC($emails);
         }
         try {
             $mail->Send();
         } catch (Exception $e) {
             $success = false;
             JLog::add($e->getMessage(), JLog::ERROR, 'kunena');
         }
     }
     return $success;
 }
Exemplo n.º 2
0
 /**
  * Send the email
  *
  * @param JMail $mail Joomla mailer
  * @return bool true on success
  */
 protected function send(&$mail)
 {
     if (($error = $mail->Send()) !== true) {
         //$info = empty($mail->ErrorInfo) ? $error->getMessage() : $mail->ErrorInfo;
         // Obtaining the problem information from Joomla mailer is a nightmare
         if (is_object($error)) {
             // It is an instance of JError. Calls the getMessage() method
             $info = $error->getMessage();
         } else {
             if (!empty($mail->ErrorInfo)) {
                 // Send() returned false. If a $mail->ErrorInfo property is set, this is the cause
                 $info = $mail->ErrorInfo;
             } else {
                 // Send() returned false, but $mail->ErrorInfo is empty. The only reasonable cause can be $mailonline = 0
                 $info = JText::_("JLIB_MAIL_FUNCTION_OFFLINE");
             }
         }
         $msg = JText::_($GLOBALS["COM_NAME"] . "_ERR_SENDING_MAIL") . ". " . $info;
         $this->MessageBoard->Add($msg, FoxMessageBoard::error);
         $this->Logger->Write($msg);
         //JLog::add($msg, JLog::ERROR, get_class($this));
         return false;
     }
     //JLog::add("Email sent.", JLog::INFO, get_class($this));
     return true;
 }