<?php

namespace App\Jobs;

use App\Models\Contact;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class SendMailWhenNewContact implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    protected $item;

    public function onConnection($connection)
    {
        $this->connection = 'redis';
        return $this;
    }

    public function __construct(Contact $contact)
    {
        $this->item = $contact;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        //
        \Mail::send('frontend3.mail.new_contact', ['item' => $this->item], function($message)
        {
            $message->to('itrosolution@gmail.com')->subject('Có một liên lạc mới tới itro.vn');
        });
    }
}
