How to send a different email for a different form in laravel?

0

I need to send an email for one form and another email for another form ie I have two forms in the same view, The first form is called user has the following fields:

  • name
  • mail
  • subject
  • comment

    When the user sends the message, an e-mail will arrive, for example, [email protected], and I have the other form that is for the company, it has the following fields:

  • name

  • nit
  • mail
  • subject
  • comment

the message should reach the email [email protected], I have no idea how to do it, is it possible to add two mail in the .env? Is there any way to configure from Mail? I'm working with laravel, I hope you understand me and help me please solve it

Thank you very much.

    
asked by Devin Stiven Zapata Areiza 11.06.2018 в 00:51
source

1 answer

3

The .env file only adds the email that sends the messages with their respective configuration, and if you want to send several emails to different recipients you can do it with the Mail class, although I do not recommend using laravel as such to send emails, you should do it through an API like sendinblue

The Mail class is imported into the controller

use Illuminate\Support\Facades\Mail;

and inside the called function write the following code

$data = array(
    'clave' => $valor,
);
Mail::send('emails.viewuser', $data, function ($message) {
        $message->from('[email protected]','Registro con exito');
        $message->to('[email protected]')->subject('Hay un nuevo registro');
});

Mail::send('emails.viewempresa', $data, function ($message) {
        $message->from('[email protected]','Registro con exito');
        $message->to('[email protected]')->subject('Hay un nuevo registro');
});

where 'emails.view' is the view that you will see in the mail (I guess this is where the form goes), $ data is the data that the view receives (in case you pass it), maybe I did not understand your question well but basically this is the way to send two different emails

    
answered by 11.06.2018 / 01:37
source