Explorar el Código

setup from mail address

olinox14 hace 1 año
padre
commit
3a0e488d2a

+ 1 - 0
.env

@@ -15,4 +15,5 @@ CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$'
 MAILER_DSN=smtp://localhost
 ###< symfony/mailer ###
 
+FROM_EMAIL=noreply@mail.ogene.fr
 CONTACT_EMAIL=olivier.massot@ogene.fr

+ 0 - 1
.idea/vcs.xml

@@ -2,6 +2,5 @@
 <project version="4">
   <component name="VcsDirectoryMappings">
     <mapping directory="$PROJECT_DIR$" vcs="Git" />
-    <mapping directory="$PROJECT_DIR$/cv2-api" vcs="Git" />
   </component>
 </project>

+ 1 - 0
config/services.yaml

@@ -11,6 +11,7 @@ services:
         autowire: true      # Automatically injects dependencies in your services.
         autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
         bind:
+            $fromEmail: '%env(FROM_EMAIL)%'
             $contactEmail: '%env(CONTACT_EMAIL)%'
 
     # makes classes in src/ available to be used as services

+ 1 - 1
src/ApiResource/ContactRequest.php

@@ -29,7 +29,7 @@ class ContactRequest
 
     #[Assert\Length(
         min: 10,
-        minMessage: 'Name must be at least {{ limit }} characters long',
+        minMessage: 'Message must be at least {{ limit }} characters long',
     )]
     protected string $message;
 

+ 8 - 3
src/State/Processor/ContactRequestProcessor.php

@@ -16,7 +16,8 @@ class ContactRequestProcessor implements ProcessorInterface
 {
     public function __construct(
         private readonly MailerInterface $symfonyMailer,
-        private readonly string $contactEmail
+        private readonly string $fromEmail,
+        private readonly string $contactEmail,
     )
     {}
 
@@ -34,9 +35,13 @@ class ContactRequestProcessor implements ProcessorInterface
 
         $symfonyMail = (new Email())
             ->to($this->contactEmail)
-            ->from($contactRequest->getEmail())
+            ->from($this->fromEmail)
             ->subject('Contact from cv.ogene.fr')
-            ->text('Name: ' . $contactRequest->getName() ?? '-' . "\n\n" . $contactRequest->getMessage());
+            ->text(
+                'From : ' . $contactRequest->getEmail() . "\n" .
+                'Name: ' . $contactRequest->getName() ?? '-' . "\n\n" .
+                $contactRequest->getMessage()
+            );
 
         $this->symfonyMailer->send($symfonyMail);