【问题标题】:Problems trying to send email with Laravel 5.5尝试使用 Laravel 5.5 发送电子邮件时出现问题
【发布时间】:2017-12-21 15:20:23
【问题描述】:

我用 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天浩:

<?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
            ]);
    }    
}

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

会是什么?

【问题讨论】:

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


    【解决方案1】:

    可能有多种原因:

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

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

    public function __construct($inputs)
    

    但你跑了:

    ->send(new DataManifestationMail());
    

    不传递任何值

    【讨论】:

    • 是的,我已经准备好输入的配置,但是我决定在传递参数之前测试发送
    • 由于这不起作用,我首先尝试解决这个问题
    • 至于我已经用于在该 PC 上测试其他 API 的端口,另外我使用在网络上运行的系统上使用的电子邮件对其进行了测试,但它也无法正常工作,所以我认为我什至没有打电话给Mail::to
    • @Mate 你确定你正在使用这个控制器方法吗?
    • @Mate 你运行php artisan queue:work 命令了吗?看来您的邮件是在队列中发送的,所以您应该启动工作程序来开始处理电子邮件(并且可能会发送电子邮件,否则您将在laravel.log 中收到错误)
    猜你喜欢
    • 2018-07-29
    • 2018-05-16
    • 1970-01-01
    • 2022-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-23
    相关资源
    最近更新 更多