Support the ongoing development of Laravel.io →
posted 10 years ago
Mail
Last updated 1 year ago.
0

I suspect this is because when using a closure (anonymous function) in PHP, if not explicitly passing the variables through - you need to use the "use" keyword so that they're available for use...

$subj = $_POST['subject'];

Mail::send('emails.contactmessage', array('from' => $sendername, 'email' => $email, 'msg' => $msg), function($message) use ($subj) {
  $message->to('[email protected]', 'Joe User')->subject($subj);
});

Also, when dealing with querystring (get) or form post data, you should use Laravel's helpers - e.g. Input::get('subject')

Last updated 1 year ago.
0

Nice.

And it works!

And I suppose I can populate other fields in anonymous functions with this 'trick'.

Thanks,

Bill

Last updated 1 year ago.
0

Hi AndrewBNZ,

Very nice, Thank you.

Regards, Sambhav

AndrewBNZ said:

I suspect this is because when using a closure (anonymous function) in PHP, if not explicitly passing the variables through - you need to use the "use" keyword so that they're available for use...

$subj = $_POST['subject'];

Mail::send('emails.contactmessage', array('from' => $sendername, 'email' => $email, 'msg' => $msg), function($message) use ($subj) {
 $message->to('[email protected]', 'Joe User')->subject($subj);
});

Also, when dealing with querystring (get) or form post data, you should use Laravel's helpers - e.g. Input::get('subject')

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.