diff --git a/smtp.php b/smtp.php index fea5465..9757c4d 100644 --- a/smtp.php +++ b/smtp.php @@ -25,7 +25,7 @@ class smtp * answer in this time, an exception is raised */ public $timeout = 10; /** Activate STARTTLS if needed. Allowed values : none, may, encrypt*/ - public $starttls = "may"; + public $starttls = "none"; /** The authentication methods in an array. Allowed : plain, login*/ public $authmethods = array ("plain", "login"); /** The socket of the connection */ @@ -36,7 +36,8 @@ class smtp { if ($this->ssl) $this->server = "tls://$this->server"; - $this->debug ("####SMTP Connection to $this->server:$this->port\n"); + $this->debug ("####SMTP Connection to $this->server:$this->port (". + date ("Y/m/d H:i:s").")\n"); $this->smtpStream = @fsockopen ($this->server, $this->port, $errno, $errstr, $this->timeout); @@ -55,8 +56,16 @@ class smtp if ($this->starttls === "may" || $this->starttls === "encrypt") { $this->putLine ("STARTTLS\r\n"); - stream_socket_enable_crypto ($this->smtpStream, true, - STREAM_CRYPTO_METHOD_TLS_CLIENT); + // The track_errors permit to create the $php_errormsg in case of + // warning + ini_set('track_errors', 1); + if (@stream_socket_enable_crypto ($this->smtpStream, true, + STREAM_CRYPTO_METHOD_TLS_CLIENT) === + false) + throw new \Exception (sprintf (_("Can't activate STARTTLS : %s"), + $php_errormsg), 500); + ini_set('track_errors', 0); + $this->debug ("STARTTLS ACTIVATED\n"); } } elseif ($this->starttls === "encrypt") @@ -149,6 +158,8 @@ class smtp while (1) { $line = stream_get_line ($this->smtpStream, 1024, "\r\n"); + if ($line === false) + break; $meta = stream_get_meta_data ($this->smtpStream); if ($meta["timed_out"] !== FALSE) {