Laravel - cannot send message without a sender address

281 views Asked by At

I have trouble with sending multiple jobs in Laravel.

Sometimes it working all right.

Sometimes I got this message cannot send message without a sender address in failed_job table and just 1 one worked.

Sometimes both not working.

And that's in my local but on the server it not working at all.

I'm trying to clear cache, config, everything but it just not work at all.

And I don't think it because my setting on .env cause it not always got errors.

Just sometimes got errors sometimes work.

The most common error is 1 working and 1 not.

enter image description here enter image description here

It just running 1 job and 1 job will throw fail in failed_job table

JOBS

class SendContactContentEmail implements ShouldQueue
{
    use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    public $data;
    public $emails;
    public $tries = 5;
    /**
     * Create a new job instance.
     *
     * @param array $_data
     */
    public function __construct(
        $_data
    )
    {
        $this->data = $_data;
        $this->emails = config('email.admin');
    }
    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $content = new ContactContentEmail($this->data);
        if (!empty($this->emails)){
            foreach ($this->emails as $email){
                Mail::to($email)->send($content);
            }
        }
    }
}
class SendContactEmail implements ShouldQueue
{
    use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    protected $email_address;
    public $tries = 5;
    /**
     * Create a new job instance.
     *
     * @param string $_email_address
     */
    public function __construct(
        string $_email_address
    )
    {
        $this->email_address = $_email_address;
    }
    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $email = new ContactEmail();
        Mail::to($this->email_address)->send($email);
    }
}

Mails

class ContactContentEmail extends Mailable
{
    use Queueable, SerializesModels;
    protected $data;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($_data)
    {
        $this->data = $_data;
    }
    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('contact.emails.contact_content')->with([
                'data' => $this->data
            ]);
    }
}
class ContactEmail extends Mailable
{
    use Queueable, SerializesModels;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct()
    {
    }
    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('contact.emails.contact');
    }
}

Controller

public function send(ContactFormRequest $request){
     $data = $request->validated();
     dispatch(new SendContactContentEmail($data));
     dispatch(new SendContactEmail($data['mail_address']));
}

Config Email

return [
    'admin' => [
        'kuriyama' => '[email protected]',
        'negishi' => '[email protected]',
    ]
];

ENV

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=xxxxxx
MAIL_ENCRYPTION=tls
[email protected]
MAIL_FROM_NAME="${APP_NAME}"
1

There are 1 answers

0
Josh Alecyan On

Can you call this command?

php artisan config:cache