src/Controller/OffreJobController.php line 20
<?phpnamespace App\Controller;use App\Form\JobFormType;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\Annotation\Route;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\Mailer\MailerInterface;use Symfony\Component\Mime\Address;use Symfony\Bridge\Twig\Mime\TemplatedEmail;use Flasher\Toastr\Prime\ToastrFactory;use Symfony\Component\Mailer\Exception\TransportExceptionInterface;use Symfony\Component\HttpFoundation\File\UploadedFile;class OffreJobController extends AbstractController{#[Route('/{_locale<%app.supported_locales%>}/jobs/offreJob/', name: 'app_offreJob', options: ['sitemap' => true], methods: ['GET', 'POST'])]public function index(Request $request, MailerInterface $mailer, ToastrFactory $toastr): Response{$type = $request->query->get('type', 'jobUn'); //sujet du mail$application = [];$form = $this->createForm(JobFormType::class, $application);//$form = $this->createForm(JobFormType::class);$form->handleRequest($request);if ($form->isSubmitted() && $form->isValid()) {$application = $form->getData();// Définition du sujet du mail selon le poste visé$subject = match ($type) {'jobUn' => 'bbcs.be - Candidature – Titre 1','jobDeux' => 'bbcs.be - Candidature – Titre 2',default => 'bbcs.be - Candidature'};$jobTitle = match ($type) {'jobUn' => 'Titre 1','jobDeux' => 'Titre 2',};$email = (new TemplatedEmail())->from('no-reply@bbcs-ovh.com')->to(new Address('info@bbcs.be'))->subject($subject)->htmlTemplate('mail/job_application_form.html.twig')->context(['application' => $application]);// Ajouter la pièce jointe si elle existeif (isset($application['cv']) && $application['cv'] instanceof UploadedFile) {$cvFile = $application['cv'];$email->attachFromPath($cvFile->getPathname(),$cvFile->getClientOriginalName(),$cvFile->getMimeType());}try {$mailer->send($email);$toastr->success('<strong>Nous avons bien reçu votre candidature! Nous y répondrons dans les meilleurs délais.</strong>')->timeOut(5000)->progressBar()->closeButton()->positionClass('toast-top-center')->flash();return $this->redirectToRoute('app_offreJob');} catch (TransportExceptionInterface $e) {echo $e->getMessage();}return $this->redirectToRoute('app_offreJob', [], Response::HTTP_SEE_OTHER);}return $this->render('jobs/offreJob/index.html.twig', ['form' => $form->createView(),'active_menu' => 'offreJob','type' => $type]);}}