Exemplo n.º 1
0
 /**
  * Try to send example mail.
  *
  * @return void
  */
 public function actionDefault()
 {
     $recipients = array('*****@*****.**');
     $subject = 'Send emails from Nette';
     $body = 'SMTP client working!';
     //enable SMTP debug messages
     Nette\Mail\SMTP\SMTPClient::$debugMode = TRUE;
     $mailer = $this->getContext()->getService('nette.mailer');
     $message = $this->getContext()->createNette__mail();
     $undelivered = array();
     foreach ($recipients as $email) {
         try {
             if (!preg_match('/^\\s*$/', $email)) {
                 $message->addTo($email);
             }
         } catch (InvalidArgumentException $e) {
             $undelivered[] = $email;
         }
     }
     $message->setSubject($subject);
     $message->setBody($body);
     ob_start();
     try {
         $message->send();
         $undelivered = array_merge($undelivered, $mailer->getUndeliveredRecipients());
         if (count($undelivered) > 0) {
             $this->result = $undelivered;
         } else {
             $this->result = TRUE;
         }
     } catch (Nette\InvalidStateException $e) {
         $this->result = FALSE;
     } catch (Nette\IOException $e) {
         $this->result = FALSE;
     }
     $this->smtpLog = ob_get_clean();
 }