isSMTP(); $mailer->Host = $host; $mailer->Port = $port; // SMTPSecure 映射:ssl→隐式 SMTPS;tls→STARTTLS;none/未知→明文。 // 明文场景必须显式关闭 SMTPAutoTLS:PHPMailer 默认会对明文会话自动尝试 // STARTTLS 升级,Mailpit 等纯明文本地服务会被误判为失败。 if ($secure === 'ssl') { $mailer->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; } elseif ($secure === 'tls') { $mailer->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; } else { $mailer->SMTPSecure = ''; $mailer->SMTPAutoTLS = false; } // SMTP 认证仅在配置了用户名时启用(Mailpit 等本地无认证服务不设置) if ($user !== '') { $mailer->SMTPAuth = true; $mailer->Username = $user; $mailer->Password = $pass; } $mailer->CharSet = 'UTF-8'; $mailer->isHTML(true); $mailer->setFrom($from, $fromName); $mailer->addAddress((string) ($target['target_addr'] ?? '')); $mailer->Subject = $title; $mailer->Body = '