Sending E-mail to different accounts Laravel

0

Has anyone made or is it possible for each form in the site to send the data to different emails in Laravel?

Exemplifying: Contact form sends the data to [email protected]

Budget form submits data to [email protected]

    
asked by anonymous 18.03.2018 / 01:58

2 answers

0

If you can set the recipient on each submission, imagine that the following code is in the controller that receives the post from the contact form:

Mail::send('emails.contato', ['title' => $title, 'content' => $content], function ($message)
{

    $message->from($request->from);

    $message->to('[email protected]');

});

And the following code in the controller that receives the post from the budget form

Mail::send('emails.contato', ['title' => $title, 'content' => $content], function ($message)
{

    $message->from($request->from);

    $message->to('[email protected]');

});

Note the line $message->to(destinatario) is this way you can send emails to different mailboxes of your choice.

There are several ways to send emails, see the link documentation

This tutorial exemplifies a complete way of putting together an email functionality: link

    
30.03.2018 / 22:53
0

To do it dynamically you need to do this:

//Busca e Retorna o Usuario que você precisa enviar o email
$user = User::findOrFail($id);

/**
 * Note o uso do "use ($user)" depois do function($m)
 * dessa forma você pode passar dinamicamente dados para o envio do email
 */
Mail::send('emails.reminder', ['user' => $user], function ($m) use ($user) {
   $m->from('[email protected]', 'Your Application');
   $m->to($user->email, $user->name)->subject('Your Reminder!');
});
    
01.04.2018 / 00:44