connection = @stream_socket_client( "tcp://{$server}:{$port}", $errno, $errstr, $timeout ); if ( is_resource( $this->connection ) ) { stream_set_timeout( $this->connection, $timeout ); } else { throw new ezcMailTransportException( "Failed to connect to the server: {$server}:{$port}." ); } } /** * Send $data to the server through the connection. * * This method appends one line-break at the end of $data. * * @throws ezcMailTransportSmtpException if there is no valid connection. * @param string $data * @return void */ public function sendData( $data ) { if ( is_resource( $this->connection ) ) { if ( fwrite( $this->connection, $data . self::CRLF, strlen( $data ) + strlen( self::CRLF ) ) === false ) { throw new ezcMailTransportException( 'Could not write to the stream. It was probably terminated by the host.' ); } } } /** * Returns one line of data from the stream. * * The returned lined will have linebreaks removed if the $trim option is set. * * @param bool $trim * @throws ezcMailTransportSmtpConnection if there is no valid connection. * @return string */ public function getLine( $trim = false ) { $data = ''; $line = ''; $loops = 0; if ( is_resource( $this->connection ) ) { while ( ( strpos( $line, self::CRLF ) === false ) && $loops < 100 ) { $line = fgets( $this->connection, 512 ); $data .= $line; $loops++; } if ( $trim == false ) { return $data; } else { return rtrim( $data, "\r\n" ); } } throw new ezcMailTransportSmtpException( 'Could not read from the stream. It was probably terminated by the host.' ); } /** * Closes the connection to the server if it is open. * * @return void */ public function close() { if ( is_resource( $this->connection ) ) { fclose( $this->connection ); $this->connection = null; } } } ?>