{"record":{"id":"acf466e28e99c810","repo":"ellite/Wallos","slug":"this-lang-smtp-connect-failed","errorCode":null,"errorMessage":"$this->lang('smtp_connect_failed')","messagePattern":"\\$this->lang\\('smtp_connect_failed'\\)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"libs/PHPMailer/PHPMailer.php","lineNumber":2024,"sourceCode":"     * Returns false if there is a bad MAIL FROM, RCPT, or DATA input.\n     *\n     * @see PHPMailer::setSMTPInstance() to use a different class.\n     *\n     * @uses \\PHPMailer\\PHPMailer\\SMTP\n     *\n     * @param string $header The message headers\n     * @param string $body   The message body\n     *\n     * @throws Exception\n     *\n     * @return bool\n     */\n    protected function smtpSend($header, $body)\n    {\n        $header = static::stripTrailingWSP($header) . static::$LE . static::$LE;\n        $bad_rcpt = [];\n        if (!$this->smtpConnect($this->SMTPOptions)) {\n            throw new Exception($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);\n        }\n        //Sender already validated in preSend()\n        if ('' === $this->Sender) {\n            $smtp_from = $this->From;\n        } else {\n            $smtp_from = $this->Sender;\n        }\n        if (!$this->smtp->mail($smtp_from)) {\n            $this->setError($this->lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError()));\n            throw new Exception($this->ErrorInfo, self::STOP_CRITICAL);\n        }\n\n        $callbacks = [];\n        //Attempt to send to all recipients\n        foreach ([$this->to, $this->cc, $this->bcc] as $togroup) {\n            foreach ($togroup as $to) {\n                if (!$this->smtp->recipient($to[0], $this->dsn)) {\n                    $error = $this->smtp->getError();","sourceCodeStart":2006,"sourceCodeEnd":2042,"githubUrl":"https://github.com/ellite/Wallos/blob/52820e87ca5a6e105fdbb7f1c0c681bc0cfee2fd/libs/PHPMailer/PHPMailer.php#L2006-L2042","documentation":"smtpSend() throws this critical error when smtpConnect() fails to establish and initialize a session with the SMTP server (connect, EHLO, and optional STARTTLS all failed). The message is the localized 'SMTP connect() failed' string; details are usually in $mailer->SMTPDebug output or $mailer->ErrorInfo. No mail can be sent without a live SMTP session.","triggerScenarios":"Calling send() with isSMTP() when $this->smtpConnect($this->SMTPOptions) returns false: wrong Host/port, firewall blocking outbound, server not offering expected encryption, or EHLO/STARTTLS negotiation failure on all hosts in the Host list.","commonSituations":"Typo'd SMTP host, port 25 blocked by cloud providers (AWS/GCP/DigitalOcean block it), missing PHP openssl extension for tls:// prefixes, DNS resolution failures, or trying STARTTLS against a server that only does implicit SSL.","solutions":["Enable $mailer->SMTPDebug = SMTP::DEBUG_SERVER; to see the exact connection/handshake failure.","Verify Host and Port: telnet host port (or openssl s_client -connect host:port) from the same machine.","Match encryption to server: SMTPSecure = ENCRYPTION_SMTPS with port 465, ENCRYPTION_STARTTLS with 587, or empty with 25.","Confirm the openssl extension is loaded (php -m | grep openssl) for encrypted connections.","Check firewall/provider blocks on the port and DNS resolution of the hostname."],"exampleFix":"// before\n$mailer->Host = 'smtp.gmail.com';\n$mailer->Port = 25; // blocked/STARTTLS-only service\n// after\n$mailer->Host = 'smtp.gmail.com';\n$mailer->SMTPAuth = true;\n$mailer->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;\n$mailer->Port = 587;","handlingStrategy":"retry","validationCode":"$host = parse_url('tcp://' . $mailer->Host, PHP_URL_HOST);\nif (@fsockopen($host, $mailer->Port, $errno, $errstr, 5) === false) {\n    throw new RuntimeException(\"SMTP unreachable: {$host}:{$mailer->Port} ($errstr)\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    $mailer->send();\n} catch (PHPMailer\\PHPMailer\\Exception $e) {\n    if (str_contains($mailer->ErrorInfo, 'SMTP connect() failed')) {\n        error_log('SMTP connect failed: ' . $mailer->ErrorInfo . ' host=' . $mailer->Host . ':' . $mailer->Port);\n        // retry with backoff or fall back to alternate transport\n    }\n}","preventionTips":["Smoke-test host:port reachability (fsockopen/telnet) from the production host at deploy time.","Match SMTPSecure to the correct port (465=SMTPS, 587=STARTTLS).","Ensure ext-openssl is loaded in the sending SAPI.","Watch for cloud providers blocking outbound port 25."],"tags":["php","phpmailer","smtp","connection","network"],"backgroundTag":"connection-refused","analyzedSha":"52820e87ca5a6e105fdbb7f1c0c681bc0cfee2fd","analyzedAt":"2026-09-13T14:09:30.873Z","contentChangedAt":"2026-09-13T14:09:30.873Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}