Я пытаюсь использовать Laravel -5.8 для уведомления по электронной почте с Sendgrid:
config / mail. php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.sendgrid.net'),
'port' => env('MAIL_PORT', 465),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'usersupport@laravelapp.com'),
'name' => env('MAIL_FROM_NAME', 'JFK'),
],
'encryption' => env('MAIL_ENCRYPTION', 'ssl'),
'username' => env('MAIL_USERNAME','kkkddd'),
'password' => env('MAIL_PASSWORD','@kkkdhhhs'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
'log_channel' => env('MAIL_LOG_CHANNEL'),
];
Вот функция контроллера. Контроллер
public function publish_all_posts(){
$userCompany = Auth::user()->company_id;
$userEmployee = Auth::user()->employee_id;
$userId = Auth::user()->id;
$userEmail = Auth::user()->email;
$userCode = Auth::user()->employee_code;
$userFirstName = Auth::user()->first_name;
$userLastName = Auth::user()->last_name;
$identities = DB::table('appraisal_identity')->select('id')->where('company_id', $userCompany)->where('is_current', 1)->first();
$reviewperiods = DB::table('appraisal_identity')->select('appraisal_name')->where('company_id', $userCompany)->where('is_current', 1)->first();
$reviewperiod = $reviewperiods->appraisal_name;
$linemanager = DB::table('hr_employees')->where('id', $userEmployee)->first();
$linemanageruserid = DB::table('hr_employees')->select('line_manager_id')->where('line_manager_id', $linemanager->line_manager_id)->first();
$linemanageruserids = DB::table('hr_employees')->where('id', $linemanageruserid->line_manager_id)->first();
$linemanageremails = DB::table('hr_employees')->select('email')->where('id', $linemanageruserids->id)->first();
$linemanagerfirstnames = DB::table('hr_employees')->select('first_name')->where('id', $linemanageruserids->id)->first();
$linemanagerfirstname = $linemanagerfirstnames->first_name;
$linemanagerlastnames = DB::table('hr_employees')->select('last_name')->where('id', $linemanageruserids->id)->first();
$linemanagerlastname = $linemanagerlastnames->last_name;
$linemanagerids = DB::table('hr_employees')->select('id')->where('line_manager_id', $linemanager->line_manager_id)->first();
$linemanagerid = $linemanagerids->id;
$details = [
'sent_to' => $linemanagerid,
'sent_by' => $userId,
'subject' => $userFirstName .' for '.$reviewperiod,
'greeting' => 'Dear '.$linemanagerfirstname . ' '. $linemanagerlastname . ',',
'body' => 'Your direct report (' . $userFirstName . ' ' .$userLastName. ') ',
'line1' => 'Your direct report (' . $userFirstName . ' ' .$userLastName. ') ',
'line2' => 'has just completed the 3+1 goals for the year.',
'line3' => 'Your reviews and approvals are required urgently.',
'thanks' => 'Thank you!',
'user_fullname' => $userFirstName. ' ' . $userLastName,
'user_code' => $userCode,
'user_email' => $userEmail,
'user_id' => $userId,
'line_manager_full_name' => $linemanagerfirstname. ' ' . $linemanagerlastname,
'review_periond' => $reviewperiod,
'line_manager_email' => $linemanageremail,
'line_manager_id' => $linemanagerid,
'notification_type' => 'goal setting',
];
Notification::route('mail', $details['line_manager_email'])
->notify(new \App\Notifications\Publish($details));
}
и это функция уведомления. Уведомление
class Publish extends Notification implements ShouldQueue
{
use Queueable;
public function __construct($details)
{
$this->details = $details;
}
public function via($notifiable)
{
return ['mail'];
}
public function toMail($notifiable)
{
return (new MailMessage)
->subject($this->details['subject'])
->greeting($this->details['greeting'])
->line($this->details['line1'])
->line($this->details['line2'])
->line($this->details['line3'])
->line($this->details['thanks']);
}
public function toArray($notifiable)
{
return [
//
];
}
}
Изначально, когда пользователи говорили, что они не получали никаких писем, я думал, что письма не были отправлены. В конце концов я узнал, что письма пошли на нежелательную почту.
Как мне решить эту проблему?
Спасибо