Beispiel #1
0
 public function testSend()
 {
     $message = new Message();
     $message->setText('Example text')->setTo('*****@*****.**')->setFrom('*****@*****.**')->setSubject('Example subject');
     // override mail()
     $mock = $this->getRunkitMock(array('mail'));
     $mock->expects($this->once())->method('mail')->with('', '', $message->getText(), $message->getHeaders())->willReturn(true);
     // test
     $mail = new Mail();
     $mail->send($message);
 }
Beispiel #2
0
 /**
  * Send E-mail message
  *
  * @param \Sendmail\Message $message
  *
  * @return boolean
  */
 public function send(Message $message)
 {
     $dialogue = new Dialogue($this->server, $this->port, $this->timeout);
     // SMTP-session is established, can send requests
     // is ESMTP?
     if ($dialogue->call('EHLO ' . $_SERVER['HTTP_HOST'])) {
         // open the TLS connection if need
         if ($this->secure) {
             $dialogue->call('STARTTLS');
             // after starting TLS need to say again EHLO
             $dialogue->call('EHLO ' . $_SERVER['HTTP_HOST'], true);
         }
     } else {
         $dialogue->call('HELO ' . $_SERVER['HTTP_HOST'], true);
     }
     // authorizing
     if ($this->auth_username && $this->auth_password) {
         $dialogue->call('AUTH LOGIN');
         $dialogue->call(base64_encode($this->auth_username));
         $dialogue->call(base64_encode($this->auth_password), true);
     }
     $dialogue->call('MAIL FROM: ' . $message->getFrom(), true);
     $dialogue->call('RCPT TO: ' . $message->getTo(), true);
     $dialogue->call('DATA');
     // point at the end means the end of the message
     $dialogue->call($message->getHeaders() . "\r\n\r\n" . $message->getText() . "\r\n.", true);
     // completes data transmission and close SMTP connect
     $result = $dialogue->call('QUIT');
     $dialogue->end();
     return $result;
 }
Beispiel #3
0
 public function testClone()
 {
     $this->message->setFrom($this->email);
     $new_message = clone $this->message;
     $new_message->setFrom('*****@*****.**');
     $this->assertNotEquals($this->message->getHeaders(), $new_message->getHeaders());
 }
Beispiel #4
0
 /**
  * @dataProvider getRecipients
  */
 public function testNotify(array $base, array $recipients)
 {
     $message = new Message();
     foreach ($base as $to) {
         $this->queue->add($message->setTo($to));
     }
     $this->assertEquals($this->queue, $this->queue->notify($recipients, $message));
     // check list messages
     $this->assertEquals(count($recipients) + count($base), $this->queue->count());
     $expected = array_merge($base, $recipients);
     $expected_message = new Message();
     foreach ($this->queue as $key => $message) {
         /* @var $message \Sendmail\Message */
         $expected_message->setTo($expected[$key]);
         $this->assertEquals($expected_message->getHeaders(), $message->getHeaders());
     }
 }
Beispiel #5
0
 /**
  * Send E-mail message
  *
  * @param \Sendmail\Message $message
  *
  * @return boolean
  */
 public function send(Message $message)
 {
     return mail('', '', $message->getText(), $message->getHeaders());
 }