尝试使用Laravel 5.5发送电子邮件时出现问题

时间:2017-12-21 15:20:24

标签: laravel laravel-5 laravel-5.5 laravel-mail

我使用Laravel 制作了一个 API并且正在正确注册数据

现在我试图让它触发注册确认电子邮件,但这些不会发生

我正在使用 Mailtrap 进行测试

.env我这样说:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=291ac7fdcf52bb
MAIL_PASSWORD=610b2e5e9782d3

Http/Mail/DataManifestMail.php tenho:

<?php

namespace App\Mail;

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

class DataManifestMail extends Mailable
{
    use Queueable, SerializesModels;

    protected $inputs;

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

    public function build()
    {
        return $this->view('mails.data');
    }
}

views/mails/data.blade.php我只有一条警告信息:

<h1>Test e-mail</h1>

然后在我的Http/Controller/ManifestationController.php我这样说:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Manifestation;
use App\Mail\DataManifestationMail;
use Mail;

class ManifestationController extends Controller
{
    private $manifestation;

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

    public function store(Request $request)
    {
        $nr = Manifestation::max('nrmanifestation');

        $this->manifestation->nrmanifestation = $nr + 1;  
        $this->manifestation->dspass = $request->dspass;
        $this->manifestation->eeemail = $request->eeemail;
        $this->manifestation->address = $request->address;
        $this->manifestation->name = $request->name;
        $this->manifestation->latitude = $request->latitude;
        $this->manifestation->longitude = $request->longitude;

        $this->manifestation->save();

        Mail::to('vazag@c1oramn.com')->send(new DataManifestationMail());

        return response()->json([
            'result' => 
                $this->manifestation->nrmanifestation
            ]);
    }    
}

我已经多次重读文档和我的代码,但没有发现任何错误

它有什么用?

1 个答案:

答案 0 :(得分:1)

可能有多种原因:

  • 配置已缓存(使用php artisan config:cache
  • 您使用了无效的mailtrap数据(您应该登录laravel.log文件)
  • 您的服务器以某种方式阻止2525端口

同时查看您的代码,似乎您错过了将$input参数传递给构造函数。你有:

public function __construct($inputs)

但你跑:

->send(new DataManifestationMail());

没有传递任何价值