argument('email'); // Parse email(s) - support comma-separated list $recipientEmails = array_map('trim', explode(',', $emailInput)); // Validate all emails foreach ($recipientEmails as $email) { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $this->error("Invalid email address: {$email}"); return 1; } } $this->info('Sending to: ' . implode(', ', $recipientEmails)); $this->info('Collecting ticket summary...'); // Collect ticket statistics $totalTickets = Ticket::count(); $activeTickets = Ticket::whereNull('deleted_at')->count(); $deletedTickets = Ticket::onlyTrashed()->count(); // Tickets by status $ticketsByStatus = Ticket::selectRaw('ticket_status_id, count(*) as count') ->whereNull('deleted_at') ->groupBy('ticket_status_id') ->with('ticketStatus') ->get(); // Tickets by priority $ticketsByPriority = Ticket::selectRaw('ticket_priority_id, count(*) as count') ->whereNull('deleted_at') ->groupBy('ticket_priority_id') ->with('ticketPriority') ->get(); // Tickets by severity $ticketsBySeverity = Ticket::selectRaw('ticket_severity_id, count(*) as count') ->whereNull('deleted_at') ->groupBy('ticket_severity_id') ->with('ticketSeverity') ->get(); // Tickets by category $ticketsByCategory = Ticket::selectRaw('ticket_category_id, count(*) as count') ->whereNull('deleted_at') ->groupBy('ticket_category_id') ->with('ticketCategory') ->get(); // Overdue tickets $overdueTickets = Ticket::whereNull('deleted_at') ->whereNotNull('due_date') ->whereDate('due_date', '<', Carbon::today()) ->with(['ticketStatus', 'ticketPriority', 'ticketSeverity', 'ticketCategory']) ->get(); // Tickets due today $dueTodayTickets = Ticket::whereNull('deleted_at') ->whereDate('due_date', Carbon::today()) ->with(['ticketStatus', 'ticketPriority', 'ticketSeverity', 'ticketCategory']) ->get(); // Recent tickets (created in the last 7 days) $recentTickets = Ticket::whereNull('deleted_at') ->where('created_at', '>=', Carbon::now()->subDays(7)) ->with(['ticketStatus', 'ticketPriority', 'ticketSeverity', 'ticketCategory']) ->orderBy('created_at', 'desc') ->limit(10) ->get(); // Prepare email data $data = [ 'totalTickets' => $totalTickets, 'activeTickets' => $activeTickets, 'deletedTickets' => $deletedTickets, 'ticketsByStatus' => $ticketsByStatus, 'ticketsByPriority' => $ticketsByPriority, 'ticketsBySeverity' => $ticketsBySeverity, 'ticketsByCategory' => $ticketsByCategory, 'overdueTickets' => $overdueTickets, 'dueTodayTickets' => $dueTodayTickets, 'recentTickets' => $recentTickets, 'generatedAt' => Carbon::now()->format('Y-m-d H:i:s'), ]; // Send one email to all recipients try { // Debug: Show configuration $this->line(''); $this->info('=== Mail Configuration Debug ==='); $this->info('MAIL_HOST: ' . (config('mail.mailers.smtp.host') ?: 'NOT SET')); $this->info('MAIL_PORT: ' . (config('mail.mailers.smtp.port') ?: 'NOT SET')); $this->info('MAIL_USERNAME: ' . (config('mail.mailers.smtp.username') ?: 'NOT SET')); $this->info('MAIL_ENCRYPTION: ' . (config('mail.mailers.smtp.encryption') ?: 'NOT SET')); $this->info('MAIL_FROM_ADDRESS: ' . (config('mail.from.address') ?: 'NOT SET')); $this->info('MAIL_FROM_NAME: ' . (config('mail.from.name') ?: 'NOT SET')); $this->line(''); // Send one email with all recipients // First recipient as "to", rest as "cc" $primaryEmail = $recipientEmails[0]; $ccEmails = array_slice($recipientEmails, 1); $mailInstance = Mail::to($primaryEmail); if (!empty($ccEmails)) { $mailInstance->cc($ccEmails); } $mailInstance->send(new TicketsSummaryMail($data)); $this->line(''); $this->info("✓ Email sent successfully!"); $this->info("To: {$primaryEmail}"); if (!empty($ccEmails)) { $this->info("CC: " . implode(', ', $ccEmails)); } return 0; } catch (\Exception $e) { $this->error("✗ Failed to send email: " . $e->getMessage()); return 1; } } }