Exemplo n.º 1
0
	/**
	 * Sends email.
	 * @param  NMail
	 * @return void
	 */
	public function send(NMail $mail)
	{
		$data = $mail->generateMessage();

		$this->connect();

		$from = $mail->getHeader('From');
		if ($from) {
			$from = array_keys($from);
			$this->write("MAIL FROM:<$from[0]>", 250);
		}

		foreach (array_merge(
			(array) $mail->getHeader('To'),
			(array) $mail->getHeader('Cc'),
			(array) $mail->getHeader('Bcc')
		) as $email => $name) {
			$this->write("RCPT TO:<$email>", array(250, 251));
		}

		$this->write('DATA', 354);
		$data = preg_replace('#^\.#m', '..', $data);
		$this->write($data);
		$this->write('.', 250);

		$this->write('QUIT', 221);

		$this->disconnect();
	}
Exemplo n.º 2
0
 /**
  * Sends e-mail.
  *
  * Implementation of IMailer
  * @param  Mail The mail to send (instance of Nette\Mail)
  * @return void
  *
  * @throws InvalidStateException if something went wrong
  */
 function send(NMail $mail)
 {
     $from = $mail->getHeader('From');
     //intentionally !=
     $from = $from != NULL && !empty($from) ? array_keys($from) : NULL;
     if ($from !== NULL) {
         $this->client->setFrom($from[0]);
     }
     $to = $mail->getHeader('To');
     $cc = $mail->getHeader('Cc');
     $bcc = $mail->getHeader('Bcc');
     $recipients = array();
     //intentionally !=
     $to != NULL && !empty($to) ? $recipients = array_merge($recipients, array_keys($to)) : NULL;
     $cc != NULL && !empty($cc) ? $recipients = array_merge($recipients, array_keys($cc)) : NULL;
     $bcc != NULL && !empty($bcc) ? $recipients = array_merge($recipients, array_keys($bcc)) : NULL;
     $this->client->setRecipients($recipients);
     $this->client->setBody($mail->generateMessage());
     //throws InvalidStateException
     $this->client->send();
 }