What if I want to use different email addresses depending on the relatedness of the form.
For example, I want to use donotreply@domain.com
for my contact form. Then I want to use myemail@domain.com
for my registration form. How can I implement this?
I've already tried to use the from
method but didn't work. Please see my code below.
Mail::later(10,
[],
compact('inputs'),
function($m) use ($email, $inputs){
$m->from('myemail@domain.com', 'Name');
$m->to($email)->subject($inputs['subject']);
}
);
In your code I think
compact('inputs')
will create an array with key 'inputs',better you should use $inputs
instead of compact('inputs')
as if
$input = [
'subject' => 'some subject'
]
and using compact
$xyz = compact('inputs') will make it
[
'inputs' => [
'subjuect' => 'some subject'
]
]
In Laravel 5.8
In your mailable class for every mail type you can set different sender in build method like
class UserRegistered extends Mailable
{
public function build()
{
return $this->from('myemail@domain.com')
->view('emails.users.registered');
}
}
and
class CntactForSubmitted extends Mailable
{
public function build()
{
return $this->from('donotreply@domain.com')
->view('emails.contact-form.submitted');
}
}
Refer docs