Home > Software design >  I am getting error about email in Laravel project
I am getting error about email in Laravel project

Time:09-01

I have a problem to solve. However, this problem came to me from sentry.io. So I didn't see the problem directly.

The problem is as follows: Address in mailbox given [] does not comply with RFC 2822, 3.6.2.

enter image description here

The problem with sentry.io is in the picture. However, as far as I understand, the problem is not directly caused by this file. In other words, the problem is in sending mail, so since email is used here, it shows the problem here. I have not used services such as laravel mailing before, so I have no idea right now.

I can share with you the necessary codes, files, etc., so that we can better understand the problem.

CodePudding user response:

Send Mail

Mail::to($user->email)->send(new NothingListenedFor3Days($user));

Mail Class

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class NothingListenedFor3Days extends Mailable
{
    use Queueable, SerializesModels;

    protected $user;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($user)
    {
        $this->user = $user;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->subject('Your Subject')
            ->view('Your blade file path')->with('user',$this->user);
    }
}

For reference link

CodePudding user response:

@Ali Raza I made both files as I shared below. Are there any mistakes I've made?

EmailCronJobController.php

Mail::to($user->email)->send(new NothingListenedFor3Days($user));

NothingListenedFor3Days.php


namespace App\Mail\Listener;

use App\Course;
use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class NothingListenedFor3Days extends Mailable
{
    use Queueable, SerializesModels;

    public $listener;
    public $random_contents;
    public $fromEmail = '[email protected]';
    public $fromName = 'Omnicourse';
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct(User $listener)
    {
        $this->listener = $listener;
        $this->random_contents = Course::all()->random(10);
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->from($this->fromEmail,$this->fromName)
            ->view('email.listener.nothing_listened_for_3_days')->with('user',$this->listener);
            ->text('email.listener.nothing_listened_for_3_days_plain')
            ->subject("Let's move ahead together");
    }
}
  • Related