Esempio n. 1
0
 /**
  * This function is used to override the send function in Joomla
  */
 public static function getMailer($mailing, $html = 0)
 {
     $fromname = empty($mailing->fromname) ? trim($GLOBALS[JNEWS . 'sendmail_name']) : trim($mailing->fromname);
     $fromemail = empty($mailing->fromemail) ? trim($GLOBALS[JNEWS . 'sendmail_email']) : trim($mailing->fromemail);
     $frombounce = empty($mailing->frombounce) ? trim($GLOBALS[JNEWS . 'sendmail_from']) : trim($mailing->frombounce);
     if (empty($fromemail)) {
         $my = JFactory::getUser();
         $userSender = jNews_Subscribers::getUsers('gid', '50', $my->id);
         $fromemail = $userSender[0]->email;
         if (empty($fromemail)) {
             jnews::printM('no', 'The sender email needs to be specified in the configuration.');
             return false;
         }
     }
     if (empty($frombounce)) {
         $frombounce = $fromemail;
     }
     $attachments = $mailing->attachments;
     $images = $mailing->images;
     $conf = JFactory::getConfig();
     $frombounceName = $fromname ? $fromname : $conf->get('config.fromname');
     if (empty($fromemail)) {
         $fromemail = trim($conf->get('config.mailfrom'));
     }
     if (empty($fromname)) {
         $fromname = trim($conf->get('config.fromname'));
     }
     jimport('joomla.mail.mail');
     $phpmailerPath = JPATH_LIBRARIES . DS . 'phpmailer' . DS;
     $mail = new JMail();
     $mail->PluginDir = $phpmailerPath;
     $mail->SetLanguage('en', $phpmailerPath . 'language' . DS);
     $mail->WordWrap = 150;
     //      	$mail->addCustomHeader("X-Mailer: ".JNEWS_JPATH_LIVE);
     //      	$mail->addCustomHeader("X-MessageID: $mailing->id");
     if ($GLOBALS[JNEWS . 'mail_format'] == '1') {
         $mail->Encoding = 'base64';
     }
     if ($GLOBALS[JNEWS . 'minisendmail']) {
         $frombounceName = '';
     }
     if (!empty($frombounce)) {
         if (version_compare(JVERSION, '3.0.0', '<')) {
             $mail->addReplyTo(array($frombounce, $frombounceName));
         } else {
             $mail->addReplyTo(array($frombounce));
         }
         JRequest::setVar('bounceBackEmail', $frombounce);
     }
     $mail->From = trim($fromemail);
     if ($GLOBALS[JNEWS . 'minisendmail']) {
         $mail->FromName = '';
     } else {
         $mail->FromName = $fromname;
     }
     $mail->Sender = trim($GLOBALS[JNEWS . 'sendmail_from']);
     if (empty($mail->Sender)) {
         $mail->Sender = '';
     }
     switch ($GLOBALS[JNEWS . 'emailmethod']) {
         case 'mail':
             $mail->IsMail();
             break;
         case 'sendmail':
             $mail->IsSendmail();
             $mail->Sendmail = $GLOBALS[JNEWS . 'sendmail_path'] ? $GLOBALS[JNEWS . 'sendmail_path'] : $conf->get('config.sendmail');
             break;
         case 'smtp':
             $mail->IsSMTP();
             $mail->Host = $GLOBALS[JNEWS . 'smtp_host'] ? $GLOBALS[JNEWS . 'smtp_host'] : $conf->get('config.smtphost');
             $mail->Port = $GLOBALS[JNEWS . 'smtp_port'] ? $GLOBALS[JNEWS . 'smtp_port'] : $conf->get('config.smtpport');
             $mail->SMTPSecure = $GLOBALS[JNEWS . 'smtp_secure'] ? $GLOBALS[JNEWS . 'smtp_secure'] : '';
             if ((bool) $GLOBALS[JNEWS . 'smtp_auth_required']) {
                 $mail->SMTPAuth = $GLOBALS[JNEWS . 'smtp_auth_required'];
                 $mail->Password = $GLOBALS[JNEWS . 'smtp_password'];
                 $mail->Username = $GLOBALS[JNEWS . 'smtp_username'];
             }
             break;
         default:
             $mail->Mailer = $conf->get('config.mailer');
             break;
     }
     if (!empty($attachments)) {
         foreach ($attachments as $attachment) {
             if (basename($attachment) !== 'index.html') {
                 $mail->AddAttachment(JNEWS_JPATH_ROOT_NO_ADMIN . $GLOBALS[JNEWS . 'upload_url'] . DS . basename($attachment));
             }
         }
     }
     switch (substr(strtoupper(PHP_OS), 0, 3)) {
         case "WIN":
             $mail->LE = "\r\n";
             break;
         case "MAC":
         case "DAR":
             $mail->LE = "\r";
         default:
             break;
     }
     return $mail;
 }