{
  "id": "php/stream-socket-ssl-sni",
  "signature": "Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14094458:SSL routines:ssl3_read_bytes:tlsv1 unrecognized name in /var/www/app/src/Mailer/SmtpTransport.php:25",
  "signature_zh": "警告: stream_socket_enable_crypto(): SSL 操作失败，代码 1。OpenSSL 错误信息: error:14094458:SSL routines:ssl3_read_bytes:tlsv1 unrecognized name，位于 /var/www/app/src/Mailer/SmtpTransport.php:25",
  "regex": "Warning: stream_socket_enable_crypto\\(\\): SSL operation failed with code 1\\. OpenSSL Error messages: error:14094458:SSL routines:ssl3_read_bytes:tlsv1 unrecognized name in .* on line \\d+",
  "domain": "php",
  "category": "protocol_error",
  "subcategory": null,
  "root_cause": "The SSL/TLS handshake fails because the server's hostname does not match the SNI (Server Name Indication) extension sent by PHP, often due to a missing or incorrect peer_name in the stream context.",
  "root_cause_type": "generic",
  "root_cause_zh": "SSL/TLS 握手失败，因为服务器的主机名与 PHP 发送的 SNI（服务器名称指示）扩展不匹配，通常由于流上下文中缺少或错误的 peer_name。",
  "versions": [
    {
      "version": "PHP 8.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "PHP 8.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "PHP 8.3",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "OpenSSL 1.1.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "OpenSSL 3.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Disabling SSL verification (verify_peer=false) bypasses the error but exposes the connection to man-in-the-middle attacks; it does not fix the SNI mismatch.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Updating the CA certificate bundle alone does not resolve SNI issues; the peer_name must explicitly match the server's certificate CN or SAN.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Set the 'peer_name' context option to the correct hostname: $context = stream_context_create(['ssl' => ['peer_name' => 'mail.example.com']]); $stream = stream_socket_client('tls://mail.example.com:465', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);",
      "success_rate": 0.9,
      "how": "Set the 'peer_name' context option to the correct hostname: $context = stream_context_create(['ssl' => ['peer_name' => 'mail.example.com']]); $stream = stream_socket_client('tls://mail.example.com:465', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);",
      "condition": "",
      "sources": []
    },
    {
      "action": "If using PHP's built-in mail function or PHPMailer, ensure the SMTP host matches the certificate's common name. For example, use 'smtp.example.com' instead of an IP address.",
      "success_rate": 0.85,
      "how": "If using PHP's built-in mail function or PHPMailer, ensure the SMTP host matches the certificate's common name. For example, use 'smtp.example.com' instead of an IP address.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Enable SNI by default in PHP 8.2+: set 'sni_enabled' to true in the stream context: stream_context_set_option($context, 'ssl', 'sni_enabled', true);",
      "success_rate": 0.75,
      "how": "Enable SNI by default in PHP 8.2+: set 'sni_enabled' to true in the stream context: stream_context_set_option($context, 'ssl', 'sni_enabled', true);",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Set the 'peer_name' context option to the correct hostname: $context = stream_context_create(['ssl' => ['peer_name' => 'mail.example.com']]); $stream = stream_socket_client('tls://mail.example.com:465', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);",
    "If using PHP's built-in mail function or PHPMailer, ensure the SMTP host matches the certificate's common name. For example, use 'smtp.example.com' instead of an IP address.",
    "Enable SNI by default in PHP 8.2+: set 'sni_enabled' to true in the stream context: stream_context_set_option($context, 'ssl', 'sni_enabled', true);"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.php.net/manual/en/context.ssl.php",
  "official_doc_section": null,
  "error_code": "14094458",
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.82,
  "resolvable": "true",
  "first_seen": "2024-06-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}