title: Laravel - How to prevent Laravel mails from going into junk mails
body: <p>I am trying to use Laravel-5.8 for email notification with Sendgrid:</p>
  
  <p>config/mail.php</p>
  
  <pre><code>return [
  
    'driver' =&gt; env('MAIL_DRIVER', 'smtp'),
  
    'host' =&gt; env('MAIL_HOST', 'smtp.sendgrid.net'),
  
    'port' =&gt; env('MAIL_PORT', 465),
  
    'from' =&gt; [
      'address' =&gt; env('MAIL_FROM_ADDRESS', 'usersupport@laravelapp.com'),
      'name' =&gt; env('MAIL_FROM_NAME', 'JFK'),
    ],
  
    'encryption' =&gt; env('MAIL_ENCRYPTION', 'ssl'),
  
    'username' =&gt; env('MAIL_USERNAME','kkkddd'),
  
    'password' =&gt; env('MAIL_PASSWORD','@kkkdhhhs'),
  
    'sendmail' =&gt; '/usr/sbin/sendmail -bs',
  
    'markdown' =&gt; [
       'theme' =&gt; 'default',
  
      'paths' =&gt; [
          resource_path('views/vendor/mail'),
      ],
    ],
  
    'log_channel' =&gt; env('MAIL_LOG_CHANNEL'),
  
  ];
  </code></pre>
  
  <p>Here is the controller function.
  Controller</p>
  
  <pre><code>public function publish_all_posts(){
      $userCompany = Auth::user()-&gt;company_id;
      $userEmployee = Auth::user()-&gt;employee_id;    
      $userId = Auth::user()-&gt;id;
      $userEmail = Auth::user()-&gt;email;
      $userCode = Auth::user()-&gt;employee_code;
      $userFirstName = Auth::user()-&gt;first_name;
      $userLastName = Auth::user()-&gt;last_name;   
  
  
      $identities = DB::table('appraisal_identity')-&gt;select('id')-&gt;where('company_id', $userCompany)-&gt;where('is_current', 1)-&gt;first();
      $reviewperiods = DB::table('appraisal_identity')-&gt;select('appraisal_name')-&gt;where('company_id', $userCompany)-&gt;where('is_current', 1)-&gt;first();
      $reviewperiod = $reviewperiods-&gt;appraisal_name;       
  
      $linemanager = DB::table('hr_employees')-&gt;where('id', $userEmployee)-&gt;first();
      $linemanageruserid = DB::table('hr_employees')-&gt;select('line_manager_id')-&gt;where('line_manager_id', $linemanager-&gt;line_manager_id)-&gt;first();
  
      $linemanageruserids = DB::table('hr_employees')-&gt;where('id', $linemanageruserid-&gt;line_manager_id)-&gt;first();      
      $linemanageremails = DB::table('hr_employees')-&gt;select('email')-&gt;where('id', $linemanageruserids-&gt;id)-&gt;first();
  
      $linemanagerfirstnames = DB::table('hr_employees')-&gt;select('first_name')-&gt;where('id', $linemanageruserids-&gt;id)-&gt;first();
      $linemanagerfirstname = $linemanagerfirstnames-&gt;first_name;
      $linemanagerlastnames = DB::table('hr_employees')-&gt;select('last_name')-&gt;where('id', $linemanageruserids-&gt;id)-&gt;first();
      $linemanagerlastname = $linemanagerlastnames-&gt;last_name;
      $linemanagerids = DB::table('hr_employees')-&gt;select('id')-&gt;where('line_manager_id', $linemanager-&gt;line_manager_id)-&gt;first();
      $linemanagerid = $linemanagerids-&gt;id;
  
      $details = [
          'sent_to' =&gt; $linemanagerid,
          'sent_by' =&gt; $userId,
          'subject' =&gt; $userFirstName .' for '.$reviewperiod,
          'greeting' =&gt; 'Dear '.$linemanagerfirstname . ' '. $linemanagerlastname . ',',
          'body' =&gt;  'Your direct report (' . $userFirstName . ' ' .$userLastName. ') ',
          'line1' =&gt; 'Your direct report (' . $userFirstName . ' ' .$userLastName. ') ',
          'line2' =&gt; 'has just completed the 3+1 goals for the year.',
          'line3' =&gt; 'Your reviews and approvals are required urgently.',
          'thanks' =&gt; 'Thank you!',            
          'user_fullname' =&gt; $userFirstName. ' ' . $userLastName,
          'user_code' =&gt; $userCode,
          'user_email' =&gt; $userEmail,
          'user_id' =&gt; $userId,
          'line_manager_full_name' =&gt; $linemanagerfirstname. ' ' . $linemanagerlastname,
          'review_periond' =&gt; $reviewperiod,
          'line_manager_email' =&gt; $linemanageremail,
          'line_manager_id' =&gt; $linemanagerid,
          'notification_type' =&gt; 'goal setting',
  
      ];  
  
      Notification::route('mail', $details['line_manager_email'])
                  -&gt;notify(new \App\Notifications\Publish($details));
  
  }
  </code></pre>
  
  <p>and this is the notification function.
  Notificatiion</p>
  
  <pre><code>class Publish extends Notification implements ShouldQueue
  {
   use Queueable;
  
   public function __construct($details)
   {
      $this-&gt;details = $details;
   }
  
   public function via($notifiable)
   {
      return ['mail'];
   }
  
   public function toMail($notifiable)
   {
      return (new MailMessage)
                  -&gt;subject($this-&gt;details['subject'])
                  -&gt;greeting($this-&gt;details['greeting'])
                  -&gt;line($this-&gt;details['line1'])
                  -&gt;line($this-&gt;details['line2'])
                  -&gt;line($this-&gt;details['line3'])
                  -&gt;line($this-&gt;details['thanks']);
   }        
  
   public function toArray($notifiable)
   {
      return [
          //
      ];
   }
  }
  </code></pre>
  
  <p>Initially when users said they didn't receive any email, I thought that mails were not sent. Eventually I found out that the mails went to junk mail.</p>
  
  <p>How do I resolve this?</p>
  
  <p>Thank you</p>