创建电子邮件发送命令 - Laravel 5.2

时间:2016-04-12 10:25:33

标签: php laravel

我创建了一个每天自动发送电子邮件的命令。

我正在创建这样的命令:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;

class SendEmail extends Command
{
    protected $signature = 'emails:send';

    protected $description = 'Sending emails to the users.';

    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
        $data = array(
            'name' => "МГ 'Константин Величков', гр. Пазарджик",
        );

        Mail::send('emails.test', $data, function ($message) {

            $message->from('mg.kvelichkov@gmail.com', 'МГ "Константин Величков"');

            $message->to('yoannam1502@gmail.com')->subject('Оценки');

        });
        $this->info('The emails are send successfully!');
    }
}

然后在内核中注册它:

<?php

namespace App\Console;



use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    protected $commands = [
        Commands\Inspire::class,
        Commands\SendEmail::class,
    ];

    protected function schedule(Schedule $schedule)
    {
        $schedule->command('emails:send')->daily();
    }
}

我列出了所有工匠命令,我可以看到我的新命令电子邮件:发送 - 因此它已创建,但当我尝试运行它时(php artisan emails:send)我得到了这个:

 [Swift_TransportException]
  Process could not be started [The system cannot find the path specified.
  ]

有什么问题?

1 个答案:

答案 0 :(得分:1)

似乎Gmail阻止发送电子邮件或您的环境阻止连接。

转到this address解锁您的Gmail帐户。另外,请检查服务器上的防火墙设置。