sendConfirmationEmails($orderId, $customerName, $customerEmail, $cartItems, $cartTotal); // Redirect to a success page header('Location: /thank-you.php?order_id=' . $orderId); exit(); } private function sendConfirmationEmails($orderId, $customerName, $customerEmail, $cartItems, $cartTotal) { // Email to Customer $customerSubject = "Confirmação do seu Pedido #{$orderId}"; $customerHtml = "

Obrigado pela sua compra, {$customerName}!

"; $customerHtml .= "

Seu pedido #{$orderId} foi recebido e está sendo processado.

"; $customerHtml .= $this->formatOrderForEmail($cartItems, $cartTotal); MailService::sendMail($customerEmail, $customerSubject, $customerHtml); // Email to Admin $adminEmail = getenv('MAIL_TO') ?: getenv('MAIL_FROM'); if ($adminEmail) { $adminSubject = "Novo Pedido Recebido #{$orderId}"; $adminHtml = "

Novo Pedido de {$customerName} ({$customerEmail})

"; $adminHtml .= $this->formatOrderForEmail($cartItems, $cartTotal); MailService::sendMail($adminEmail, $adminSubject, $adminHtml); } } private function formatOrderForEmail($items, $total) { $html = ''; $html .= ''; $html .= ''; foreach ($items as $item) { $html .= sprintf('', htmlspecialchars($item['name']), $item['quantity'], $item['price'], $item['price'] * $item['quantity'] ); } $html .= ''; $html .= sprintf('', $total); $html .= '
ProdutoQtdPreçoSubtotal
%s%dR$ %.2fR$ %.2f
Total:R$ %.2f
'; return $html; } } if (isset($_POST['action']) && $_POST['action'] === 'checkout') { $orderController = new OrderController(); $orderController->checkout(); } ?>