Laravel 7x API没有发送邮件警报

时间:2020-09-10 21:17:56

标签: php laravel api model-view-controller alert

当我尝试使用Postman或Insomnia进行POST来存储带有数据的电子邮件时,我不明白为什么。

我有以下字段:

public function up()
        {
            Schema::create('polls', function (Blueprint $table) {
                $table->id();
                $table->text('now');
                $table->json('paramJson');
                $table->enum('status', ['a', 'b', 'c','d'])->default('a');
            });
        }

投票模型:

protected $fillable = ['now'];
protected $casts = ['paramJson' => 'array'];

PollsController.php

public function store(Request $request)
    {
        $poll = request->all();
        if($poll['status']=='b')
        {
            Mail::to('example@....com')->send(new NotifyPoll($poll));
        }

        return response()->json(Poll::create($poll), 201);
    }

Mail / NotifyPoll

namespace App\Mail;

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

class NotifyPoll extends Mailable
{
    use Queueable, SerializesModels;

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

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->from('.......@inbox.mailtrap.io')->subject('Error Poll')->view('mail.notifyErrorPoll',['mail_data'=>$this->itemPoll]);
    }
}

失眠的一面,我没有收到任何错误消息,但不幸的是,邮件没有到达。

1 个答案:

答案 0 :(得分:0)

我认为您错过了protected $itemPoll类中的NotifyPoll。另外,检查您的日志文件以获取错误堆栈。调试时有很大帮助。