Bogardo / Mailgun

Mailgun package for Laravel
MIT License
295 stars 116 forks source link

ERROR when passing a variable to to() #154

Open D-sense opened 5 years ago

D-sense commented 5 years ago

Hi,

I get an error each time I try passing a variable to the to(). Example: ->to($user_email_address, 'John Doe')

In addition, is it possible to use this with Mailable? Like passing mailable as opposed to passing email path?

Is there any way around this? Thanks

cosmini commented 5 years ago

You'll have to use inheritance see anonymous functions here https://www.php.net/manual/en/functions.anonymous.php

Step 3 is what you're after

$user_email_address = 'foo@bar.com';
Mailgun::send('foo.bar', ['foo' => 'bar], function ($message) use ($user_email_address) {
  $message->to($user_email_address, 'John Doe');
});

Note the keyword use