I created a command that sends a mail to all emails of newsletter. it works fine in localhost but does not work in directadmin.
i typed php artisan send:mail2
in localhost's console in the path of laravel and it works
command name is send:mail2
. here my command:
<?php
namespace App\Console\Commands;
use App;
use Carbon\Carbon;
use App\Mail\NewsLetter;
use Illuminate\Support\Facades\Mail;
use Illuminate\Console\Command;
class SendMail extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'send:mail2';
/**
* 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()
{
//::where('created_at','>=',Carbon::parse('yesterday 3pm'))
$posts = App\posts::all()->pluck('id')->toArray();
$mails = App\newsletters::all()->pluck('email')->toArray();
foreach($posts as $p){
echo $p;
foreach($mails as $m){
Mail::to($m)->send(new NewsLetter($p));
}
}
}
}
here my cronjobs command:
* * * * * /usr/local/bin/php /home/mohamm30/domains/mohammadrezababaei.ir/public_html/moshavere php artisan send:mail2 >> /dev/null 2>&1
my username : mohamm30
my domain : mohammadrezababaei.ir