Dear {$customerName},
Please find your invoice attached to this email.
Order Details
| Order Number | {$order->order_number} |
|---|---|
| Order Date | {$order->created_at->format('d M Y')} |
| Total Amount | R {$order->total} |
Thank you for your order!
first(); if (!$order) { return response()->json(['error' => 'Order not found'], 404); } try { // Generate invoice $invoicePath = InvoiceService::generateInvoice($order); // Get the full path from public disk $fullPath = storage_path('app/public/' . $invoicePath); Log::info('Invoice test:', [ 'order_number' => $orderNumber, 'stored_path' => $invoicePath, 'full_path' => $fullPath, 'file_exists' => file_exists($fullPath), ]); if (file_exists($fullPath)) { return response()->file($fullPath); } else { return response()->json([ 'error' => 'Invoice file not found', 'path' => $invoicePath, 'full_path' => $fullPath, ], 500); } } catch (\Exception $e) { Log::error('Invoice test error:', [ 'order_number' => $orderNumber, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString(), ]); return response()->json([ 'error' => 'Failed to generate invoice', 'message' => $e->getMessage() ], 500); } })->name('test-invoice'); // Test route to send an invoice email via Mailjet // Usage: http://localhost:8000/test-email/{order_number}/{email} Route::get('/test-email/{orderNumber}/{email}', function ($orderNumber, $email) { $order = Order::where('order_number', $orderNumber)->first(); if (!$order) { return response()->json(['error' => 'Order not found'], 404); } try { // Generate invoice $invoicePath = InvoiceService::generateInvoice($order); $fullPath = storage_path('app/public/' . $invoicePath); if (!file_exists($fullPath)) { return response()->json([ 'error' => 'Invoice file not found', 'path' => $invoicePath, 'full_path' => $fullPath, ], 500); } // Send email directly via Mailjet (no queue needed) $mailjetService = new MailjetService(); $customerName = $order->customer_name ?? explode('@', $email)[0]; // Generate basic HTML for email $htmlContent = <<
Dear {$customerName},
Please find your invoice attached to this email.
| Order Number | {$order->order_number} |
|---|---|
| Order Date | {$order->created_at->format('d M Y')} |
| Total Amount | R {$order->total} |
Thank you for your order!