• Модуль: mail
  • Путь к файлу: ~/bitrix/modules/mail/lib/smtp.php
  • Класс: BitrixMailSmtp
  • Вызов: Smtp::connect
public function connect(&$error)
{
	$error = null;

	if ($this->stream)
	{
		return true;
	}

	$resource = @stream_socket_client(
		$this->options['socket'], $errno, $errstr, $this->options['timeout'],
		STREAM_CLIENT_CONNECT, $this->options['context']
	);

	if ($resource === false)
	{
		$error = $this->errorMessage(Smtp::ERR_CONNECT, $errno ?: null);
		return false;
	}

	$this->stream = $resource;

	if ($this->options['timeout'] > 0)
	{
		stream_set_timeout($this->stream, $this->options['timeout']);
	}

	$prompt = $this->readResponse();

	if (false === $prompt)
	{
		$error = $this->errorMessage(array(Smtp::ERR_CONNECT, Smtp::ERR_COMMUNICATE));
	}
	else if (!preg_match('/^ 220 ( rn | x20 ) /x', end($prompt)))
	{
		$error = $this->errorMessage(array(Smtp::ERR_CONNECT, Smtp::ERR_REJECTED), trim(end($prompt)));
	}

	if ($error)
	{
		return false;
	}

	if (!$this->capability($error))
	{
		return false;
	}

	if (!$this->options['tls'] && preg_grep('/^ STARTTLS $/ix', $this->sessCapability))
	{
		if (!$this->starttls($error))
		{
			return false;
		}
	}

	return true;
}