Have you checked your hosting Firewall rules?
Feb 27, 2021
3
Level 8
Sending mail every hour issue
Hi, I can't manage to send emails every hour with laravel.
Here is my code:
file \app\console\commands\RappelDepot.php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
use App\Mail\RappelDepotFichiers;
class RappelDepot extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rappel:dixjours';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Envoie un mail de rappel 10 jours après la fin d une formation';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
Mail::to('[email protected]')->send(new RappelDepotFichiers());
}
}
kernel.php :
<?php
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\RappelDepot::class,
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('rappel:dixjours')
->hourly();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
when i run this command : php artisan rappel:dixjours , i get this error:
[email protected] (php/7.3/production/stable) ~/espaceformation $ php artisan rappel:dixjours
Swift_TransportException
Connection could not be established with host smtp.mailtrap.io :stream_socket_client(): unable to connect to tcp://smtp.mailtrap.io:2525 (Connection refused)
at vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:261
257▕ }
258▕ $streamContext = stream_context_create($options);
259▕
260▕ set_error_handler(function ($type, $msg) {
➜ 261▕ throw new Swift_TransportException('Connection could not be established with host '.$this->params['host'].' :'.$msg);
262▕ });
263▕ try {
264▕ $this->stream = stream_socket_client($host.':'.$this->params['port'], $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $streamContext);
265▕ } finally {
1 [internal]:0
Swift_Transport_StreamBuffer::{closure}("stream_socket_client(): unable to connect to tcp://smtp.mailtrap.io:2525 (Connection refused)", "/home/bxxxxxxxxxh/exxxxxxxxxxxxn/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php")
+12 vendor frames
14 app/Console/Commands/RappelDepot.php:42
Illuminate\Mail\PendingMail::send(Object(App\Mail\RappelDepotFichiers))
.env file : (every other mail i send in controllers are working fine)
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=xxxxxxxxxxxxxx38
MAIL_PASSWORD=fxxxxxxxxxxxxxx2
MAIL_ENCRYPTION=tls
[email protected]
MAIL_FROM_NAME="${APP_NAME}"
What am I doing wrong ?
Thank you
Please or to participate in this conversation.