public function testConstructWithAHtmlMessage()
 {
     $from = 'Domain <*****@*****.**>';
     $to = '*****@*****.**';
     $subject = 'subject';
     $message = "Hello\n\nThis is a <strong>test</strong> message.";
     $mail = new Message();
     $mail->setFrom($from);
     $mail->setTo($to);
     $mail->setSubject($subject);
     $mail->setMessage($message);
     $mail->setIsHtmlMessage(true);
     $expectedHeaders = array('From: Domain <*****@*****.**>', 'To: info <*****@*****.**>', 'MIME-Version: 1.0');
     $expectedHeaders = implode("\n", $expectedHeaders);
     $messageParser = new MessageParser($mail);
     $headers = implode("\n", $messageParser->getHeaders());
     $body = $messageParser->getBody();
     $this->assertEquals($subject, $messageParser->getSubject());
     $this->assertContains($expectedHeaders, $headers);
     $this->assertContains($message, $body);
     $this->assertContains(strip_tags($message), $body);
     $this->assertContains('Content-Type: multipart/alternative; boundary=', $headers);
     $this->assertContains('Content-Type: text/html; charset=utf-8', $body);
     $this->assertContains('Content-Type: text/plain; charset=utf-8', $body);
 }
Exemple #2
0
 /**
  * Appends a message to a mailbox
  * @param string $mailbox The mailbox to append the message to
  * @param zibo\library\mail\Message $message The message to append
  * @return null
  * @throws zibo\library\mail\exception\MailException when th message could not be appended to the mailbox
  */
 public function appendMessage($mailbox, Message $message)
 {
     $parser = new MessageParser($message);
     $message = 'Subject: ' . $parser->getSubject() . "\r\n";
     $message .= implode("\r\n", $parser->getHeaders());
     $message .= "\r\n\r\n" . $parser->getBody();
     $connection = $this->getConnection($mailbox);
     $stream = $connection->getStream();
     $reference = $connection->getReference();
     if (!imap_append($stream, $reference, $message)) {
         throw new MailException('Could not append the message to ' . $mailbox . ': ' . imap_last_error());
     }
 }
 /**
  * Deliver a mail message to the server mail transport using PHP's mail function
  * @param zibo\library\mail\Message $message The message to send
  * @param array $variables Array containing variables to replace in the mail body
  * @return null
  * @throws zibo\ZiboException when the message is not accepted for delivery. Check the installation of the mail tools on the server.
  */
 public function send(Message $message, array $variables = array())
 {
     $parser = new MessageParser($message, $variables);
     $subject = $parser->getSubject();
     $body = $parser->getBody();
     $headers = $parser->getHeaders();
     $headersString = $this->implodeHeaders($headers);
     $additionalParameters = null;
     $returnPath = $message->getReturnPath();
     if ($returnPath) {
         $additionalParameters = '-f ' . $returnPath->getEmailAddress();
     }
     $result = mail(null, $subject, $body, $headersString, $additionalParameters);
     $this->logMail($subject, $headersString, $result);
     if (!$result) {
         throw new MailException('The message is not accepted for delivery. Check your mail configuration on the server.');
     }
 }