尝试使用 Laravel 5.5 发送电子邮件时遇到问题
Problems trying to send email with Laravel 5.5
我用 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
]);
}
}
我已经多次重读文档和我的代码,没有发现任何错误
它可以是什么?
可能有多种原因:
- 配置已缓存(使用
php artisan config:cache
)
- 您使用了无效的 mailtrap 数据(您应该登录
laravel.log
文件)
- 您的服务器以某种方式阻止了
2525
端口
同时查看您的代码,您似乎错过了将 $input
参数传递给构造函数。你有:
public function __construct($inputs)
但是你运行:
->send(new DataManifestationMail());
不传递任何值
我用 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
]);
}
}
我已经多次重读文档和我的代码,没有发现任何错误
它可以是什么?
可能有多种原因:
- 配置已缓存(使用
php artisan config:cache
) - 您使用了无效的 mailtrap 数据(您应该登录
laravel.log
文件) - 您的服务器以某种方式阻止了
2525
端口
同时查看您的代码,您似乎错过了将 $input
参数传递给构造函数。你有:
public function __construct($inputs)
但是你运行:
->send(new DataManifestationMail());
不传递任何值