0

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

iraj jelodari
  • 3,118
  • 3
  • 35
  • 45
taher
  • 159
  • 1
  • 10

2 Answers2

0

You don't need to php before artisan. Please try the following command * * * * * cd /home/mohamm30/domains/mohammadrezababaei.ir/public_html/moshavere && php artisan send:mail2 >> /dev/null 2>&1

webdevtr
  • 480
  • 2
  • 6
0

you can try this

*   *   *   *   *   /usr/local/bin/php /home/mohamm30/domains/mohammadrezababaei.ir/public_html/moshavere/artisan send:mail2 >> /dev/null 2>&1

make sure your PHP path is /usr/local/bin/php and artisan file in /home/mohamm30/domains/mohammadrezababaei.ir/public_html/moshavere/artisan

you can find the PHP command path from which php command in your terminal.

Shahadat Hossain
  • 947
  • 9
  • 24