简体   繁体   English

Laravel通知未发送

[英]Laravel Notifications not sending

I set up a contact form which sends an email on completion using Laravel notifications, however it doesn't look like anything is being sent. 我设置了一个联系表单,该表单在使用Laravel通知完成后会发送一封电子邮件,但是看起来并没有发送任何东西。

ROUTES ROUTES

Route::post('/contact', 'ContactController@store');

CONTROLLER CONTROLLER

public function store()
{
    request()->validate([
        'name' => 'required|max:255',
        'email' => 'required|email|unique:contacts|max:255',
        'message' => 'required|max:2000',
    ]);

    $contact = Contact::create(
        request()->only([
            'name',
            'email',
            'message',
        ])
    );

    User::first()->notify(new SendContactNotification($contact));

    return back()->with('success', 'Thank you, I will be in touch as soon as I can');
}

NOTIFICATION 通知

protected $contact;


public function __construct($contact)
{
    $this->contact = $contact;
}

public function toMail($notifiable)
{
    return (new MailMessage)
                ->line($this->contact->name)
                ->line($this->contact->email)
                ->line($this->contact->message);
}

I do get the success message when I run it. 运行时,我确实会收到成功消息。 However, nothing appears in my Mailtrap. 但是,我的邮件陷阱中没有任何内容。 Here's the mail section of the sanitised .env file: 这是经过清理的.env文件的mail部分:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=username
MAIL_PASSWORD=password
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS='admin@test.com'
MAIL_FROM_NAME='admin'

I can't see what I have done wrong. 我看不到我做错了什么。 I also tried type hinting the contact in the notification like so: 我也尝试在提示中键入提示联系人的内容,如下所示:

public function __construct(Contact $contact)
{
    $this->contact = $contact;
}

That didn't work unfortunately. 不幸的是,这没有用。 I also thought it might be something to do with my computer not being set up to send emails using php, but I was under the impression that the env file would take care of that. 我还认为这可能与我的计算机未设置为使用php发送电子邮件有关,但我的印象是env文件可以解决这一问题。

The contacts are being stored in the database ok, but no emails are being sent. 可以将联系人存储在数据库中,但是没有发送电子邮件。 Would anyone be able to help? 有人可以帮忙吗?

It was the port in the env file, I changed it to: 它是env文件中的端口,我将其更改为:

MAIL_PORT=465

and it worked! 而且有效!

I knew port 2525 wasn't working because of this answer: https://stackoverflow.com/a/45418259/5497241 我知道端口2525不能工作,因为这个答案: https : //stackoverflow.com/a/45418259/5497241

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM