loic-sharma / Messages

A Laravel Bundle for the Swiftmailer library
GNU Lesser General Public License v3.0
39 stars 7 forks source link

Attaching data to views inline? #18

Closed tommykent1210 closed 11 years ago

tommykent1210 commented 11 years ago

According to the docs, there are two ways of sending mail. The first is like the following:

        Message::send(function($message)
        {
            $message->to($email);
            $message->from($from_email);

            $message->subject($subject);
            $message->body('view: emails.verify');

            // You can add View data by simply setting the value
            // to the message.
            $message->body->verify_link = $activationURL;

            $message->html(true);
        });

But this tells me that "email is undefined" at the $message->to() line. I'm using this inside of a function withing the user controller (maybe the problem? Can functions sit within functions in PHP?)

So, I tried the inline version (lack of function within a function surely helps) but alas I can't figure out how to bind data to the email view :/

loic-sharma commented 11 years ago

If you have the email variable defined outside the anonymous function passed to the send function you'll need to do:

Message::send(function($message) use($email, $from_email)