Esempio n. 1
0
 /**
  * Constructor.
  *
  * The first argument may be an array of all options. If so, it must include
  * the 'host' and 'port' keys in order to ensure that all required values 
  * are present.
  *
  * @param  string|array $host 
  * @param  null|integer $port
  * @param  null|array   $config
  * @return void
  * @throws Exception\InvalidArgumentException
  */
 public function __construct($host = '127.0.0.1', $port = null, array $config = null)
 {
     // Did we receive a configuration array?
     if (is_array($host)) {
         // Merge config array with principal array, if provided
         if (is_array($config)) {
             $config = array_replace_recursive($host, $config);
         } else {
             $config = $host;
         }
         // Look for a host key; if none found, use default value
         if (isset($config['host'])) {
             $host = $config['host'];
         } else {
             $host = '127.0.0.1';
         }
         // Look for a port key; if none found, use default value
         if (isset($config['port'])) {
             $port = $config['port'];
         } else {
             $port = null;
         }
     }
     // If we don't have a config array, initialize it
     if (null === $config) {
         $config = array();
     }
     if (isset($config['ssl'])) {
         switch (strtolower($config['ssl'])) {
             case 'tls':
                 $this->_secure = 'tls';
                 break;
             case 'ssl':
                 $this->_transport = 'ssl';
                 $this->_secure = 'ssl';
                 if ($port == null) {
                     $port = 465;
                 }
                 break;
             default:
                 throw new Exception\InvalidArgumentException($config['ssl'] . ' is unsupported SSL type');
                 break;
         }
     }
     // If no port has been specified then check the master PHP ini file. Defaults to 25 if the ini setting is null.
     if ($port == null) {
         if (($port = ini_get('smtp_port')) == '') {
             $port = 25;
         }
     }
     parent::__construct($host, $port);
 }
Esempio n. 2
0
 /**
  * Constructor.
  *
  * @param  string  $host
  * @param  integer $port
  * @param  array   $config
  * @return void
  * @throws \Zend\Mail\Protocol\Exception
  */
 public function __construct($host = '127.0.0.1', $port = null, array $config = array())
 {
     if (isset($config['ssl'])) {
         switch (strtolower($config['ssl'])) {
             case 'tls':
                 $this->_secure = 'tls';
                 break;
             case 'ssl':
                 $this->_transport = 'ssl';
                 $this->_secure = 'ssl';
                 if ($port == null) {
                     $port = 465;
                 }
                 break;
             default:
                 throw new Protocol\Exception($config['ssl'] . ' is unsupported SSL type');
                 break;
         }
     }
     // If no port has been specified then check the master PHP ini file. Defaults to 25 if the ini setting is null.
     if ($port == null) {
         if (($port = ini_get('smtp_port')) == '') {
             $port = 25;
         }
     }
     parent::__construct($host, $port);
 }