laravel sendmail

配置.env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.163.com
MAIL_PORT=25
MAIL_USERNAME=myMail@163.com
MAIL_PASSWORD=******
MAIL_ENCRYPTION=null

设置 config/mail.php

'from' => ['address' => 'jzmcc@163.com', 'name' => 'testMail'],

设定测试路由

Route::get('/sendmail',function(){
    $data = array('name' => 'jordan');
    Mail::send('welcome', $data, function($message){
        $message->to('11112222@qq.com')
            ->subject('Hi there! laravel sent me!');
    });
});

 Mail::send参数:

1.welcome  邮件模板样式

2.$data     传给模板的变量

3.闭包       接受$message的实例,设置变量,交给SwiftMailer使用

队列发送

设置.env

QUEUE_DRIVER=database

生成表

php artisan queue:table
php artisan queue:failed-table
php artisan migrate

延迟5秒发送

Route::get('/mail/queue', function(){
    Mail::later(5, 'emails.queued', ['name'=>'smith'], function($m){
        $m->to('111111@qq.com', 'some name')->subject('queueTest');
    });
    return 'The email has sent.';
});
原文地址:https://www.cnblogs.com/fenle/p/4756350.html