Laravel 4 Mail not passing data

2019-02-26 08:42发布

Emails works fine with dummy data:

    Mail::send('emails.contact', $messageData, function ($message) use ($messageData) {
        $message->from('joetannorella@gmail.com', 'Joe');
        $message->to('joetannorella@gmail.com','Joe T')->subject('Email Test');
    });

But when I try to pass data into the email, it won't send. I know a common problem is not passing through data with the use ($data), but I am doing this and it's still not working.

This is my code that will not work:

    $messageData = array(
        'name' => 'test name',
        'email' => 'test email',
        'message' => 'test message'
    );

    Mail::send('emails.contact', $messageData, function ($message) Use ($messageData) {
        $message->from($messageData['email'], $messageData['name']);
        $message->to('joetannorella@gmail.com','Joe T')->subject('Email Test');
    });

I'm pretty stuck for ideas now!

Thanks

2条回答
闹够了就滚
2楼-- · 2019-02-26 09:05
$data = array( 'email' => 'sample@sample.com', 'first_name' => 'Lar', 'from' => 'sample@sample.comt', 'from_name' => 'Vel' );

Mail::send( 'email.welcome', $data, function( $message ) use ($data)
{
    $message->to( $data['email'] )->from( $data['from'], $data['first_name'] )->subject( 'Welcome!' );
});
查看更多
Anthone
3楼-- · 2019-02-26 09:13

You cannot use $message as your variable - see L4 docs here.

So change it to something like "msg" - i.e.:

   $messageData = array(
        'name' => 'test name',
        'email' => 'test email',
        'msg' => 'test message'
    );
查看更多
登录 后发表回答