mercredi 10 octobre 2018

Laravel: 5.6: Send email with a file using a command

I am trying to send an email using a command in Laravel. I would like to send a file from a specific folder. I did it previously using in a view with a form, but now I want to send the email using a command. The file will be always in the same folder. This is the command code:

<?php

 namespace efsystem\Console\Commands;

use Illuminate\Console\Command;
use Storage;
use Mail;
use Config;

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

/**
 * The console command description.
 *
 * @var string
 */
protected $description = 'Sending emails to the users';

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

/**
 * Execute the console command.
 *
 * @return mixed
 */
public function handle()
{

    $data = array(
        'destino'    => 'example@gmail.com',
        'asunto'     => 'example',
        //'a_file'     => $request['a_file']
     );

    //dd($data['destino']);

    Mail::send('administracion.email.email_body', $data, function($message) use ($data) {

        $message->to($data['destino']);
        $message->subject($data['asunto']);
        $message->from(Config::get('mail.username'));

    });

    $this->info('The emails are send successfully!');

}
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire