getOrganizationDeletionRequest(); $mail = ['subject' => '', 'content' => '']; try { $this->organizationFactory->delete($organizationCreationRequest); $mail['subject'] = 'Organization deleted'; $mail['content'] = 'The organization n° ' . $organizationCreationRequest->getOrganizationId() . ' has been deleted successfully.'; } catch (\Exception $e) { $mail['subject'] = 'Organization deletion : an error occured'; $mail['content'] = 'An error occured while deleting the new organization : \n' . $e->getMessage(); throw $e; } finally { if ($organizationCreationRequest->getSendConfirmationEmailAt() !== null) { $symfonyMail = (new SymfonyEmail()) ->from($this->opentalentMailReport) ->replyTo($this->opentalentMailReport) ->returnPath(Address::create($this->opentalentMailReport)) ->to($organizationCreationRequest->getSendConfirmationEmailAt()) ->subject($mail['subject']) ->text($mail['content']); $this->symfonyMailer->send($symfonyMail); } } } }