isError() public method

Check if an error occurred.
public isError ( ) : boolean
return boolean True if an error did occur.
Example #1
0
 /**
  * Send message
  *
  * @return boolean
  */
 public function send()
 {
     $result = false;
     $errorMessage = null;
     if ('' === $this->get('to')) {
         $errorMessage = 'Send mail FAILED: sender address is empty';
     } elseif (null === $this->mail) {
         $errorMessage = 'Send mail FAILED: not initialized inner mailer';
     } else {
         $this->errorInfo = null;
         ob_start();
         $this->mail->send();
         $error = ob_get_contents();
         ob_end_clean();
         // Check if there are any error during mail sending
         if ($this->mail->isError()) {
             $errorMessage = 'Send mail FAILED: ' . $this->prepareErrorMessage($this->mail->ErrorInfo) . PHP_EOL . $this->prepareErrorMessage($error);
             $this->errorInfo = $this->mail->ErrorInfo;
         } else {
             $result = true;
         }
     }
     if ($errorMessage) {
         $this->errorMessage = $errorMessage;
         \XLite\Logger::getInstance()->log($errorMessage, \LOG_ERR);
     }
     // Restore layout
     if (null !== $this->templatesSkin) {
         \XLite\Core\Layout::getInstance()->setSkin($this->templatesSkin);
         $this->templatesSkin = null;
     }
     $this->imageParser->unlinkImages();
     return $result;
 }
Example #2
0
 /**
  * Test error handling.
  */
 public function testError()
 {
     $this->Mail->Subject .= ': Error handling test - this should be sent ok';
     $this->buildBody();
     $this->Mail->clearAllRecipients();
     // no addresses should cause an error
     $this->assertTrue($this->Mail->isError() == false, 'Error found');
     $this->assertTrue($this->Mail->send() == false, 'send succeeded');
     $this->assertTrue($this->Mail->isError(), 'No error found');
     $this->assertEquals('You must provide at least one recipient email address.', $this->Mail->ErrorInfo);
     $this->Mail->addAddress($_REQUEST['mail_to']);
     $this->assertTrue($this->Mail->send(), 'send failed');
 }