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]
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]
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
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!');
});