Пример #1
0
 /**
  * @param	Account		$account
  * @param	array		$to
  * @param	string		$subject
  * @param	string		$bodyText
  * @param	bool		$isBodyHtml = false
  * @param	array		$attachmentsFileName = array()
  * @return	bool
  */
 protected function _SendMessage($account, $to, $subject, $bodyText, $isBodyHtml = false, $attachmentsFileName = array())
 {
     require_once WM_ROOTPATH . 'common/class_settings.php';
     require_once WM_ROOTPATH . 'common/class_account.php';
     require_once WM_ROOTPATH . 'common/class_webmailmessages.php';
     require_once WM_ROOTPATH . 'common/class_smtp.php';
     $settings =& Settings::CreateInstance();
     if (!$settings || !$settings->isLoad) {
         throw new WebMailModelException('settings error');
     }
     if (!$settings->IncludeLang()) {
         throw new WebMailModelException('lang error');
     }
     $message = new WebMailMessage();
     $GLOBALS[MailDefaultCharset] = $account->GetUserCharset();
     $GLOBALS[MailInputCharset] = $account->GetUserCharset();
     $GLOBALS[MailOutputCharset] = $account->GetDefaultOutCharset();
     $message->Headers->SetHeaderByName(MIMEConst_MimeVersion, '1.0');
     $message->Headers->SetHeaderByName(MIMEConst_XMailer, XMAILERHEADERVALUE);
     $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
     if (null !== $ip) {
         $message->Headers->SetHeaderByName(MIMEConst_XOriginatingIp, $ip);
     }
     $message->IdMsg = -1;
     $message->Uid = -1;
     $_serverAddr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['SERVER_NAME'] : 'cantgetservername';
     $message->Headers->SetHeaderByName(MIMEConst_MessageID, '<' . substr(session_id(), 0, 7) . '.' . md5(time()) . '@' . $_serverAddr . '>');
     $message->SetFromAsString($account->GetFriendlyEmail());
     $message->SetToAsString(implode(', ', $to));
     $message->SetSubject($subject);
     $message->SetDate(new CDateTime(time()));
     if ($isBodyHtml) {
         $message->TextBodies->HtmlTextBodyPart = ConvertUtils::AddHtmlTagToHtmlBody(str_replace("\n", CRLF, str_replace("\r", '', ConvertUtils::WMBackHtmlNewCode($bodyText))));
     } else {
         $message->TextBodies->PlainTextBodyPart = str_replace("\n", CRLF, str_replace("\r", '', ConvertUtils::WMBackHtmlNewCode($bodyText)));
     }
     if (count($attachmentsFileName) > 0) {
         foreach ($attachmentsFileName as $attachmentFileName) {
             $message->Attachments->AddFromFile($attachmentFileName, basename($attachmentFileName), ConvertUtils::GetContentTypeFromFileName(basename($attachmentFileName)));
         }
     }
     $message->OriginalMailMessage = $message->ToMailString(true);
     $message->Flags |= MESSAGEFLAGS_Seen;
     return CSmtp::SendMail($settings, $account, $message, $account->GetFriendlyEmail(), implode(', ', $to));
 }