简体   繁体   English

laravel 4中的每周电子邮件简报

[英]Weekly email newsletter in laravel 4

I want to send auto generated weekly newsletter from my laravel project. 我想从我的laravel项目发送自动生成的每周时事通讯。 From a controller I want to send some result of the laravel query in a newslater form to all the user in the list. 从控制器我想以新闻报表的形式将laravel查询的一些结果发送给列表中的所有用户。

At this moment I can send the mail to single user when they are knocking some operation themselves . 此时我可以将邮件发送给单个用户,因为他们自己敲了一些操作。 Now I want a auto generation of email on a particular frequent of time (day/ week /month ) ... also I want to send those mail to all the user in the db, in a loop. 现在我希望在特定频繁的时间(日/周/月)自动生成电子邮件...我也希望将这些邮件发送到数据库中的所有用户,循环播放。 thank you for helping me in this tiny research :) 谢谢你在这个小小的研究中帮助我:)

Create an artisan command : 创建一个工匠命令

php artisan command:make SendNewletterCommand

In app/commands, edit the SendNewletterCommand.php and: 在app /命令中,编辑SendNewletterCommand.php并:

Set your command name: 设置您的命令名称:

protected $name = 'newsletter:send';

Create your fire() method: 创建fire()方法:

public function fire()
{
   foreach(User::all() as $user)
   {
        Mail::send('emails.newletter', $data, function($message) use ($user)
        {
            $message->to($user->email, $user->name)->subject('Welcome!');
        });
   }
}

Register your command in artisan by editing app/start/artisan.php and adding: 通过编辑app / start / artisan.php并添加以下内容,在artisan中注册您的命令:

Artisan::add(new SendNewletterCommand);

And add your new command to your crontab: 并将新命令添加到您的crontab:

0 0 * * sun php /your/project/path/artisan newsletter:send

It will send your e-mails every sunday at midnight. 它将在午夜的每个星期天发送您的电子邮件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM