recipient = $recipient; $this->linkedProfile = $linkedProfile; $this->action = $action; } /** * Execute the job. * * @return void */ public function handle() { Log::info('SendProfileLinkChangedMail: Job starting', [ 'recipient_id' => $this->recipient->id, 'recipient_type' => get_class($this->recipient), 'recipient_email' => $this->recipient->email ?? 'NO EMAIL', 'linked_profile_id' => $this->linkedProfile->id, 'linked_profile_type' => get_class($this->linkedProfile), 'action' => $this->action, ]); // Check if recipient has an email if (empty($this->recipient->email)) { Log::warning('SendProfileLinkChangedMail: Recipient has no email address', [ 'recipient_id' => $this->recipient->id, 'recipient_type' => get_class($this->recipient), ]); return; } try { // Send the email to the recipient Mail::to($this->recipient->email)->send( new ProfileLinkChangedMail($this->recipient, $this->linkedProfile, $this->action) ); Log::info('SendProfileLinkChangedMail: Email sent successfully', [ 'recipient_email' => $this->recipient->email, 'action' => $this->action, ]); } catch (\Exception $e) { Log::error('SendProfileLinkChangedMail: Failed to send email', [ 'recipient_email' => $this->recipient->email ?? 'NO EMAIL', 'action' => $this->action, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString(), ]); throw $e; } } }