|
|
@@ -8,6 +8,7 @@ use ApiPlatform\Metadata\Operation;
|
|
|
use ApiPlatform\Metadata\Post;
|
|
|
use ApiPlatform\State\ProcessorInterface;
|
|
|
use App\ApiResource\ContactRequest;
|
|
|
+use Symfony\Component\HttpFoundation\RequestStack;
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
|
|
use Symfony\Component\Mailer\MailerInterface;
|
|
|
@@ -19,7 +20,9 @@ class ContactRequestProcessor implements ProcessorInterface
|
|
|
private readonly MailerInterface $symfonyMailer,
|
|
|
private readonly string $fromEmail,
|
|
|
private readonly string $contactEmail,
|
|
|
- private readonly string $hmacKey
|
|
|
+ private readonly string $contactEmailSauvagerie,
|
|
|
+ private readonly string $hmacKey,
|
|
|
+ private readonly RequestStack $requestStack
|
|
|
)
|
|
|
{}
|
|
|
|
|
|
@@ -49,10 +52,17 @@ class ContactRequestProcessor implements ProcessorInterface
|
|
|
throw new \RuntimeException('Invalid payload');
|
|
|
}
|
|
|
|
|
|
+ // Get the recipient parameter from the query, default to 'cv' if not provided
|
|
|
+ $request = $this->requestStack->getCurrentRequest();
|
|
|
+ $recipient = $request ? $request->query->get('recipient', 'cv') : 'cv';
|
|
|
+
|
|
|
+ // Determine the email recipient based on the recipient parameter
|
|
|
+ $emailTo = $recipient === 'sauvagerie' ? $this->contactEmailSauvagerie : $this->contactEmail;
|
|
|
+
|
|
|
$symfonyMail = (new Email())
|
|
|
- ->to($this->contactEmail)
|
|
|
+ ->to($emailTo)
|
|
|
->from($this->fromEmail)
|
|
|
- ->subject('Contact from cv.ogene.fr')
|
|
|
+ ->subject('Contact from ' . $recipient . ' website')
|
|
|
->text(
|
|
|
'From : ' . $contactRequest->getEmail() . "\n" .
|
|
|
'Name: ' . ($contactRequest->getName() ?? '-') . "\n\n" .
|
|
|
@@ -63,4 +73,4 @@ class ContactRequestProcessor implements ProcessorInterface
|
|
|
|
|
|
return $contactRequest;
|
|
|
}
|
|
|
-}
|
|
|
+}
|