function saveImapMessage($data, $folder = null) { global $osC_Session; require_once DIR_FS_CATALOG . 'ext/phpmailer/class.phpmailer.php'; $mailer = new PHPMailer(); $mailer->IsSMTP(); $mailer->CharSet = "utf-8"; $mailer->Host = $this->getSmtpHost(); $mailer->Port = $this->getSmtpPort(); $mailer->SMTPAuth = true; $mailer->Username = $this->getSmtpUsername(); $mailer->Password = $this->getSmtpPassword(); $mailer->FromName = $data['from']; $mailer->From = $data['sender']; if ($data['notification'] == 'true') { $mailer->ConfirmReadingTo = $this->getAccountEmail(); } $mailer->Subject = $data['subject']; $mailer->Body = $data['body']; $mailer->AltBody = "This is the body in plain text for non-HTML mail clients"; $mailer->Priority = $data['priority']; $mailer->IsHTML($data['content_type'] == 'html' ? true : false); foreach ($data['to'] as $to) { $mailer->AddAddress($to['email'], $to['name']); } if ($data['cc'] != null) { foreach ($data['cc'] as $cc) { $mailer->AddCC($cc['email'], $cc['name']); } } if ($data['bcc'] != null) { foreach ($data['bcc'] as $bcc) { $mailer->AddBCC($bcc['email'], $bcc['name']); } } $path = DIR_FS_CACHE_ADMIN . 'emails/attachments/' . $osC_Session->getID(); $osC_DirectoryListing = new osC_DirectoryListing($path); foreach ($osC_DirectoryListing->getFiles() as $file) { $mailer->AddAttachment($path . '/' . $file['name']); } $mailer->SetMessageType(); $raw_text = $mailer->CreateHeader() . "\r\n" . $mailer->CreateBody() . "\r\n"; if ($this->connectMailServer($folder)) { if ($this->_inbox->append_message(imap::utf7_imap_encode($folder), $raw_text)) { $this->closeMailServer(); return true; } } $this->closeMailServer(); return false; }
/** * Simple HTML and attachment test */ function test_AltBody_Attachment() { $this->Mail->Body = "This is the <strong>HTML</strong> part of the email."; $this->Mail->AltBody = "This is the text part of the email."; $this->Mail->Subject .= ": AltBody + Attachment"; $this->Mail->IsHTML(true); if (!$this->Mail->AddAttachment(__FILE__, "test_attach.txt")) { $this->assertTrue(false, $this->Mail->ErrorInfo); return; } $this->BuildBody(); $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo); if (is_writable('.')) { file_put_contents('message.txt', $this->Mail->CreateHeader() . $this->Mail->CreateBody()); } else { $this->assertTrue(false, 'Could not write local file - check permissions'); } }
function CreateBody() { $body = parent::CreateBody(); /* if ($this->ContentType != 'text/plain') { foreach ($GLOBALS['plugins'] as $plugin) { $plreturn = $plugin->mimeWrap($this->messageid,$body,$this->header,$this->ContentTypeHeader,$this->destinationemail); if (is_array($plreturn) && sizeof($plreturn) == 3) { $this->header = $plreturn[0]; $body = $plreturn[1]; $this->ContentTypeHeader = $plreturn[2]; } } } */ return $body; }