Mailgun icon indicating copy to clipboard operation
Mailgun copied to clipboard

ERROR when passing a variable to to()

Open D-sense opened this issue 5 years ago • 1 comments

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

D-sense avatar Jun 11 '19 14:06 D-sense

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 = '[email protected]';
Mailgun::send('foo.bar', ['foo' => 'bar], function ($message) use ($user_email_address) {
  $message->to($user_email_address, 'John Doe');
});

Note the keyword use

cosmini avatar Sep 02 '19 06:09 cosmini