loic-sharma / Messages

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

Is this the way I should use your bundle? #20

Closed xtrasmal closed 11 years ago

xtrasmal commented 11 years ago

Here is a better view: http://paste.laravel.com/jlU

    public function get_validate()
    {
        $username =  URI::segment(3);
        $token =  URI::segment(4);
        $user = User::where_username($username)->where_token($token)->first();
        if($user->verified != 1){
            $user->verified = 1; 
            $user->save();  
            Message::send(function($message)
            {
                $username =  URI::segment(3);
                $token =  URI::segment(4);
                $user = User::where_username($username)->where_token($token)->first();
                $appurl = URL::base();
                $uname = $user->username;
                $uemail = $user->email;
                $message->to($uemail);
                $message->from('bla@bla.eu', 'Team base');
                $message->subject('Uw account is geactiveerd');
                //$message->body('view: emails.hello');

                $message->body('
                <h1>Welkom bij Teambase</h1><br>
                <p>U kunt nu de website gebruiken</p>
                <a href="'.$appurl.'" title="Teambase">Bezoek de website</a>
                ');
                $message->html(true);
            });
            if(Message::was_sent())
            {
                return Redirect::to('/');
            }           
        } else{
            return Redirect::to('/');
        }
    }   

[feedly mini] 
loic-sharma commented 11 years ago

Yep, that looks fine, although I would recommend you use the use keyword on the function (so that you don't have to run the exact same query):

http://paste.laravel.com/jmo

xtrasmal commented 11 years ago

Great stuff, I was already working with Getters and Setters to get this working! This is better.

xtrasmal commented 11 years ago

The documentation says that I should work with email templates. THis sounds very good, but how would I use

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

in the setup above? Right now I send out an email with a link that verifies the emailaddress. Can I send the message variables to the view?

loic-sharma commented 11 years ago

Check out the readme. You can add data to the view like so:

$message->body('view: emails.hello');
$message->body->name = 'value';
xtrasmal commented 11 years ago

Thanks. I have read the readme, but you know how it goes. Somedays you are reading 1000 manuals and you start reading 10 words at a time and you miss something. Very nice. Now I will add some intelligence.

Do you have any type of workflow that you use, that I could adapt straight from the start? Do you have something like an intelligent way you work with the email layouts?

loic-sharma commented 11 years ago

No problem. I'll close this one out as well then.

Unfortunately, I don't have any suggestions for your workflow. I've never had to design a complicated email layout, so I'm not of much help.