php工匠时间表:运行不发送电子邮件

时间:2016-08-04 23:30:46

标签: php laravel email smtp

我正在尝试从预定的laravel任务发送电子邮件,当我从应用程序调用发送电子邮件的命令时,但是当从命令行调用该命令时,它会被执行但没有发送电子邮件。 我的命令代码是下一个:

namespace App\Console\Commands;

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

class SendEmails extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'emails:send';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        try {
             Mail::send('emails.testmail', [ ], function ($m) { 
                $m->to('someona@gmail.com', 'Francisco Larios')->subject('Your Reminder!'); 
            });
        } catch (\Exception $e) {
            throw new \Exception("Error Processing Request", 1);

        }

    }
}

内核文件中的代码是下一个:

namespace App\Console;

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

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        Commands\Inspire::class,
        Commands\SendEmails::class,
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    //{
    //    $schedule->command('inspire')->everyMinute();
    //}
}

我在控制台上运行的命令是:

php artisan emails:send

1 个答案:

答案 0 :(得分:0)

问题是我用来发送电子邮件的smtp服务器,我只是将它更改为mail.php配置文件中的另一个smtp服务器,因此,它适用于应用程序和命令行执行。