【发布时间】:2019-02-26 15:28:35
【问题描述】:
我正在运行一个 5.7 laravel 项目,我可以毫无问题地从控制器发送电子邮件。
但是,当我尝试使用相同的逻辑从命令行启动的命令发送电子邮件时,电子邮件不会发送并且我收到以下错误:
In AbstractSmtpTransport.php line 445:
Expected response code 220 but got an empty response
这是我的命令代码:
<?php
namespace App\Console\Commands;
use App\Email_confirmation;
use Illuminate\Console\Command;
use App;
use Carbon\Carbon;
use Illuminate\Support\Facades\Mail;
use App\Mail\ShopOrderConfirmation;
class sendEmailConfirmations extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:sendEmailConfirmations';
/**
* 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()
{
$ec_global = Email_confirmation::where("due_date" ,">", Carbon::now('Europe/Paris'))->get();
if (!$ec_global->isEmpty()) {
foreach ($ec_global as $ec) {
if (App::environment('production')) {
$subject = $ec->shop_name . " - Order confirmation";
Mail::to($ec->contact_email)
->send(new ShopOrderconfirmation($ec->contact_name, $subject, $ec->shop_name, $ec->order_date));
}
elseif (App::environment('development','test')) {
$subject = $ec->shop_name . " - Order confirmation - TEST";
Mail::to("me@whatever.net")
->send(new ShopOrderconfirmation($ec->contact_name, $subject, $ec->shop_name, $ec->order_date));
}
}
}
else {
$this->info('Empty.');
}
}
}
项目正在运行 6.0.2 版本的 swiftmailer 包。我在这里找不到行为不同的原因。
【问题讨论】:
标签: laravel email command command-line-interface