Exemple #1
0
 /** send emails
  * @param bool $showHTML show report on the screen
  * @param object $mailing contain the information of mailing
  * @param objectlist $receivers all receivers
  * @params $type (1-all types of mailings, 2-confirmation email)
  */
 function send($oneQueue, $receiver)
 {
     // we should verify that the data we get is teh proper value
     if (!is_object($oneQueue)) {
         return false;
     }
     $tags = null;
     ### create the mail
     $mail = jNews_ProcessMail::getMailer($oneQueue);
     //$frompreview param is to determine if the sending is called by 'Send Test Email'
     if (empty($mail)) {
         return false;
     }
     $tags['issuenb'] = $oneQueue->issue_nb;
     ### create content
     $this->getContent($oneQueue->images, $oneQueue->htmlcontent, $oneQueue->textonly, $oneQueue->subject, true, false, $oneQueue);
     //new $oneQueue->subject
     if ($this->cancelMailing) {
         $this->cancelMailing = false;
         return true;
         // we return true even though the mail was not sent because empty. Need improvement...
     }
     if (!empty($receiver->user_id)) {
         $tags['user_id'] = $receiver->user_id;
     }
     //Forced HTML Mailing Only?
     if ($GLOBALS[JNEWS . 'forced_html']) {
         $receiver->receive_html = 1;
     }
     $tname = explode(" ", $receiver->name);
     $firstname = $tname[0];
     $toUser = $GLOBALS[JNEWS . 'minisendmail'] ? '' : $receiver->name;
     $mail->AddAddress($receiver->email, $toUser);
     $username = empty($receiver->username) ? $firstname : $receiver->username;
     if (version_compare(JVERSION, '3.0.0', '<')) {
         $date = JHTML::_('date', jnews::getNow(), JText::_('DATE_FORMAT_LC1'), JNEWS_TIME_OFFSET);
     } else {
         $date = JHtml::_('date', jnews::getNow(), JText::_('DATE_FORMAT_LC1'), JNEWS_TIME_OFFSET);
     }
     $replaceWhat = array('{tag:name}', '{tag:firstname}', '{tag:username}', '{tag:date}');
     $replaceBy = array($receiver->name, $firstname, $username, $date);
     $sujetReplaced = str_replace($replaceWhat, $replaceBy, $oneQueue->subject);
     if (class_exists('jNews_Auto')) {
         jNews_Auto::tags($sujetReplaced, $tags);
     }
     $mail->Subject = $sujetReplaced;
     if (!empty($oneQueue->html) && $receiver->receive_html) {
         $this->html = true;
         $mail->IsHTML(true);
         $ashtml = 1;
         $mail->Body = jNews_ProcessMail::replaceTags($oneQueue->htmlcontent, $receiver, $oneQueue, $ashtml, $tags);
         $mail->AltBody = jNews_ProcessMail::replaceTags($oneQueue->textonly, $receiver, $oneQueue, $ashtml, $tags);
         //this line is added when jLinks is integrated with jNews
         //variables used in integration of jLinks
         static $mailCatID = null;
         static $convertedLinks = null;
         if (empty($oneQueue->mailing_type)) {
             $oneQueue->mailing_type = 1;
         }
         $mainframe = JFactory::getApplication();
         JPluginHelper::importPlugin('jnews');
         $jomsocial = $mainframe->triggerEvent('jnewsbot_jomsocial_members', array(&$mail->Body, &$mail->AltBody, $receiver));
         $this->_linkReplacement($oneQueue->mailing_type, $oneQueue->id, $oneQueue->subject, $mail, $mailCatID, $convertedLinks, $receiver->id);
         jNews_ProcessMail::replaceClass($mail->Body, $mail->AltBody, $receiver);
         if (!empty($oneQueue->template_id)) {
             jNews_Templates::includeStyles($mail->Body, $oneQueue->template_id);
         }
     } else {
         //text only email
         $this->html = false;
         $mail->IsHTML(false);
         $mail->AltBody = '';
         $ashtml = 0;
         $mail->Body = jNews_ProcessMail::replaceTags($oneQueue->textonly, $receiver, $oneQueue, $ashtml, $tags);
         $mail->AltBody = $this->_safe_utf8_encode($mail->Body, $mail->CharSet);
         $simpleText = '';
         jNews_ProcessMail::replaceClass($mail->Body, $simpleText, $receiver);
         if (version_compare(JVERSION, '1.6.0', '<')) {
             //j15
             $imgfolders = DS . 'images' . DS . 'stories';
         } else {
             //j16
             $imgfolders = DS . 'images' . DS . 'sampledata';
         }
         if (!empty($oneQueue->images)) {
             foreach ($oneQueue->images as $image) {
                 $img = explode('|', $image);
                 $attrib = explode("/", $img[0]);
                 $path = JNEWS_JPATH_ROOT . $imgfolders;
                 if (count($img) == 1) {
                     $imageName = $img[0];
                 } else {
                     $imageName = $attrib[count($attrib) - 1];
                     for ($index = 0; $index < sizeof($attrib) - 1; $index++) {
                         $path .= $attrib[$index] . '/';
                     }
                 }
                 $mail->AddAttachment($path . $imageName);
             }
             //endofreach
         }
     }
     jNews_ProcessMail::normalizeURL($mail->Body);
     if (!empty($oneQueue->html) && $receiver->receive_html) {
         $this->_addHTMLTagToBody($mail->Body, $sujetReplaced);
     }
     if ($GLOBALS[JNEWS . 'embed_images']) {
         $this->_embedImages($mail);
     }
     $mail->addCustomHeader("X-SubscriberID: " . base64_encode($receiver->email));
     // DKIM code addition by Amod begins
     $mail = $this->_addDKIM2($mail);
     // DKIM code addition by Amod ends
     $status = $mail->Send();
     if (version_compare(JVERSION, '1.6.0', '<')) {
         //j15
         $mailErrorCount = $mail->error_count;
     } else {
         //j16
         $mailErrorCount = !empty($mail->ErrorInfo) ? 1 : 0;
     }
     //we prompt message regarding the status of the sending if there is an error
     if (!empty($mail->ErrorInfo)) {
         echo '<br><span style="color:red;">' . $mail->ErrorInfo . '</span>';
     }
     if ($status && $mailErrorCount < 1) {
         return true;
     } else {
         jNews_ProcessMail::failMailReason($mail);
         return false;
     }
 }