_config = $config; } public function sendMail(string $to, string $title, string $html, string $accname = ''): bool { try { $mail = new PHPMailer(true); // SMTP $mail->isSMTP(); $mail->SMTPDebug = !empty($this->_config['debug']) ? 2 : 0; $mail->Host = $this->_config['host']; $mail->Port = (int)$this->_config['port']; $mail->SMTPAuth = ($this->_config['username'] ?? '') !== ''; $mail->Username = $this->_config['username']; $mail->Password = $this->_config['password']; $mail->CharSet = 'UTF-8'; // Security $secure = $this->_config['securityType'] ?? ''; if (in_array($secure, ['ssl', 'tls'], true)) { $mail->SMTPSecure = $secure; } // Sender / receiver $mail->setFrom($this->_config['email'], $this->_config['fromName']); $mail->addAddress($to, $accname); // Content $mail->isHTML(true); $mail->Subject = $title; $mail->Body = $html; // AltBody $plain = str_replace(['
', '
', '
'], "\n", $html); $plain = strip_tags($plain); $mail->AltBody = $plain; return $mail->send(); } catch (Exception $e) { // Log plutôt qu'echo error_log('Mail error: ' . $e->getMessage()); return false; } } }