예제 #1
0
 /**
  * Create a new message instance.
  *
  * @return \Mail\Message
  */
 protected function createMessage()
 {
     $message = new Message(new Swift_Message());
     // If a global from address has been specified we will set it on every message
     // instances so the developer does not have to repeat themselves every time
     // they create a new message. We will just go ahead and push the address.
     if (isset($this->from['address'])) {
         $message->from($this->from['address'], $this->from['name']);
     }
     return $message;
 }
예제 #2
0
파일: Smtp.php 프로젝트: ryanc/php-pop3
 /**
  * Send an email.
  *
  * @param Message $msg
  * @throws Protocol\Exception
  *         if the the sender address or recpients are undefined.
  * @return bool
  */
 public function send(Message $mail)
 {
     if ($mail->getFrom() === null) {
         throw new Protocol\Exception("The message does not have a from address.");
     }
     if (count($mail->getTo()) + count($mail->getCc()) + count($mail->getBcc()) < 1) {
         throw new Protocol\Exception("The message must have a recipient.");
     }
     if ($mail->getReturnPath() !== null) {
         $reversePath = $mail->getReturnPath();
     } elseif ($mail->getSender() !== null) {
         $reversePath = $mail->getSender();
     } else {
         $reversePath = $mail->getFrom()->email;
     }
     $this->mail($reversePath);
     foreach ($mail->getTo() as $recipient) {
         $this->rcpt($recipient->email);
     }
     foreach ($mail->getCc() as $recipient) {
         $this->rcpt($recipient->email);
     }
     foreach ($mail->getBcc() as $recipient) {
         $this->rcpt($recipient->email);
     }
     $data = $mail->toString();
     $this->data($data);
     $this->close();
     return true;
 }
예제 #3
0
 /**
  * Add the content to a given message.
  *
  * @param  \Mail\Message  $message
  * @param  string  $view
  * @param  string  $plain
  * @param  array   $data
  * @return void
  */
 protected function addContent($message, $view, $plain, $data)
 {
     if (isset($view)) {
         $message->setBody($this->getView($view, $data), 'text/html');
     }
     if (isset($plain)) {
         $message->addPart($this->getView($plain, $data), 'text/plain');
     }
 }
예제 #4
0
파일: SmtpTest.php 프로젝트: ryanc/php-pop3
 public function testSmtpSendHtml()
 {
     $this->_connection->ehlo();
     $this->_connection->authenticate($this->_authConfig);
     $mail = Message::newInstance()->setFrom(TESTS_MAIL_SMTP_SENDER, 'Test Sender')->addTo(TESTS_MAIL_SMTP_RECIPIENT, 'Test Recipient')->addCc(TESTS_MAIL_SMTP_CC_RECIPIENT, 'Test CC')->addBcc(TESTS_MAIL_SMTP_BCC_RECIPIENT, 'Test BCC')->setPriority(Message::PRIORITY_HIGHEST)->setUserAgent('MailKit')->setSubject("Test message from PHPUnit.")->setBody("<strong>Sent by SmtpTest::testSmtpSendHtml.")->setContentType('text/html');
     $this->assertTrue($this->_connection->send($mail));
 }