Override default mailer URL in Symfony

I am trying to give the possibility to users to send emails to me in Symfony, I could send emails to my self but I am not able to get emails from other emails because the default email adress given in the .env file is not getten override.

  /**
 * @Route("/send_msg", name="send_msg", methods={"GET","POST"})
 */
public function index(Request $request, Swift_Mailer $mailer)
{

  $name =  $request->query->get('name');
  $mail =  $request->query->get('mail');
  $msg =  $request->query->get('msg');


    $message = (new Swift_Message('Client'))
        ->setFrom($mail)
        ->setTo('[email protected]')
        ->setBody($msg)

    ;

    $mailer->send($message);
    return new JsonResponse();

}

and this is the .env file

###> symfony/mailer ###
# MAILER_DSN=smtp://localhost
###< symfony/mailer ###

 # For Gmail as a transport, use: "gmail://username:[email protected]"
 # For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
 # Delivery is disabled by default via "null://localhost"
  MAILER_URL=gmail://[email protected]:[email protected]
 ###< symfony/swiftmailer-bundle ###

    ###> symfony/sendgrid-mailer ###
    #MAILER_DSN=sendgrid://[email protected]
    ###< symfony/sendgrid-mailer ###

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *