Overview

Namespaces

  • Jyxo
    • Beholder
      • TestCase
    • Gettext
      • Parser
    • Input
      • Chain
      • Filter
      • Validator
    • Mail
      • Email
        • Attachment
      • Parser
      • Sender
    • Rpc
      • Json
      • Xml
    • Shell
    • Spl
    • Svn
    • Time
    • Webdav
  • PHP

Classes

  • FileSystem
  • HttpResponse
  • Imap
  • JsonRpc
  • Memcached
  • Mysql
  • Pgsql
  • PhpExtension
  • PhpVersion
  • PhpZend
  • Smtp
  • Webdav
  • XmlRpc
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: /**
  4:  * Jyxo PHP Library
  5:  *
  6:  * LICENSE
  7:  *
  8:  * This source file is subject to the new BSD license that is bundled
  9:  * with this package in the file license.txt.
 10:  * It is also available through the world-wide-web at this URL:
 11:  * https://github.com/jyxo/php/blob/master/license.txt
 12:  */
 13: 
 14: namespace Jyxo\Beholder\TestCase;
 15: 
 16: /**
 17:  * Tests SMTP server availability.
 18:  *
 19:  * @category Jyxo
 20:  * @package Jyxo\Beholder
 21:  * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
 22:  * @license https://github.com/jyxo/php/blob/master/license.txt
 23:  * @author Jaroslav HanslĂ­k
 24:  */
 25: class Smtp extends \Jyxo\Beholder\TestCase
 26: {
 27:     /**
 28:      * Hostname.
 29:      *
 30:      * @var string
 31:      */
 32:     private $host;
 33: 
 34:     /**
 35:      * Recipient.
 36:      *
 37:      * @var string
 38:      */
 39:     private $to;
 40: 
 41:     /**
 42:      * Sender.
 43:      *
 44:      * @var string
 45:      */
 46:     private $from;
 47: 
 48:     /**
 49:      * Timeout.
 50:      *
 51:      * @var integer
 52:      */
 53:     private $timeout;
 54: 
 55:     /**
 56:      * Constructor.
 57:      *
 58:      * @param string $description Test description
 59:      * @param string $host Hostname
 60:      * @param string $to Recipient
 61:      * @param string $from Sender
 62:      * @param integer $timeout Timeout
 63:      */
 64:     public function __construct($description, $host, $to, $from = '', $timeout = 2)
 65:     {
 66:         parent::__construct($description);
 67: 
 68:         $this->host = (string) $host;
 69:         $this->to = (string) $to;
 70:         $this->from = (string) $from;
 71:         $this->timeout = (int) $timeout;
 72: 
 73:         // Default sender
 74:         if (empty($this->from)) {
 75:             $this->from = 'beholder@jyxo.com';
 76:         }
 77:     }
 78: 
 79:     /**
 80:      * Performs the test.
 81:      *
 82:      * @return \Jyxo\Beholder\Result
 83:      */
 84:     public function run()
 85:     {
 86:         // The \Jyxo\Mail\Sender\Smtp class is required
 87:         if (!class_exists('\Jyxo\Mail\Sender\Smtp')) {
 88:             return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::NOT_APPLICABLE, 'Class \Jyxo\Mail\Sender\Smtp missing');
 89:         }
 90: 
 91:         try {
 92:             $header = 'From: ' . $this->from . "\n";
 93:             $header .= 'To: ' . $this->to . "\n";
 94:             $header .= 'Subject: Beholder' . "\n";
 95:             $header .= 'Date: ' . date(DATE_RFC822) . "\n";
 96: 
 97:             $smtp = new \Jyxo\Mail\Sender\Smtp($this->host, 25, $this->host, $this->timeout);
 98:             $smtp->connect()
 99:                 ->from($this->from)
100:                 ->recipient($this->to)
101:                 ->data($header, 'Beholder SMTP Test')
102:                 ->disconnect();
103:         } catch (\Exception $e) {
104:             $smtp->disconnect();
105:             return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Send error %s', $this->host));
106:         }
107: 
108:         // OK
109:         return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::SUCCESS, $this->host);
110:     }
111: }
112: 
Jyxo PHP Library API documentation generated by ApiGen 2.3.0