安排发送电子邮件

问题描述:

我想用Laravel 5调度程序来发送应用程序电子邮件。我正在使用此代码。安排发送电子邮件

// app/Console/Kernal.php 
$schedule->call(function() 
{ 
    $newsletter = Newsletter::first()->toArray(); 

    Mail::send('emails.newsletter', $newsletter, function($message) 
    { 
     $message->to('[email protected]', 'John Doe')->subject('Test'); 
    }); 

})->cron('* * * * *'); 

然后我在终端手动调用它(现在)与php artisan schedule:run。终端返回Running scheduled command: Closure,没有其他事情发生。

当我将代码更改为此时,第一个通讯正在被删除。所以它必须是Mail的问题。有没有人有任何想法?

$schedule->call(function() 
{ 
    $newsletter = Newsletter::first(); 

    $newsletter->delete(); 

})->cron('* * * * *'); 
+0

很难说没有一些额外的细节。 resources/views/emails/newsletter.blade.php是否存在?当你转储$消息时,你看到了什么? – Jason 2015-03-09 18:17:25

+0

@Jason是的,这种观点存在。当我将该代码放入任何控制器方法中作为测试时,该电子邮件可以正常发送。但我正在努力使它从时间表中发出。 – Staysee 2015-03-10 01:21:08

我想通了。我认为这只是我的邮件配置问题。我切换到smtp,一切正常。

你有没有解决这个问题?我现在有这个确切的问题。它说,你可以发送电子邮件的唯一方法是:

$schedule->command('foo')->sendOutputTo('path to file')->semailOutputTo('[email protected]'); 

但没有格式,或者你可以从我所看到的任何附加的消息。

+0

我认为这只是我的邮件配置问题。我切换到smtp并使用[mailtrap](https://mailtrap.io)进行测试。一切似乎都很好。 – Staysee 2015-08-08 20:22:42