0

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.

iguner
  • 51
  • 8
  • ```Mail::to($user->email)```, isn't it ? – Paul J.K Aug 31 '22 at 11:07
  • @フクちゃん How should I change the selected line in the photo like this? – iguner Aug 31 '22 at 11:10
  • you need to go ```EmailCronJobController.php``` file – Paul J.K Aug 31 '22 at 11:12
  • @フクちゃん Ok, now this file is in front of me. ```foreach ($users as $user){ if($user->getCustomField('nothing_listened_3_days_email_send_date')==null){ Mail::to($user)->send(new NothingListenedFor3Days($user)); $user->setCustomField('nothing_listened_3_days_email_send_date',date('Y-m-d H:i:s')); }``` – iguner Aug 31 '22 at 11:15
  • change `Mail::to($user)` to `Mail::to($user->email)` – Vüsal Hüseynli Aug 31 '22 at 12:48

2 Answers2

0

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

Ali Raza
  • 670
  • 5
  • 15
  • Hi, I shared what I did as an answer below. I would be very happy if you could look at it and tell me if there is any mistake. @Ali Raza – iguner Aug 31 '22 at 14:20
0

@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 = 'listener@omnicourse.io';
    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");
    }
}
iguner
  • 51
  • 8