我建立了一个联系表单,但它发送了两封邮件而不是一封。以下是控制器代码:
这是ClientContact邮件类:
<?php
namespace App\Http\Controllers;
use App\Http\Requests\ContactFormRequest;
use App\Mail\ClientContact;
use Illuminate\Support\Facades\Mail;
class ContactController extends Controller
{
/**
* It sends a contact request and returns
* the user back to the contact form.
* @param ContactFormRequest $request
* @return mixed
*/
public function send(ContactFormRequest $request)
{
Mail::send(new ClientContact($request->only(['name','email','message'])));
session()->flash('success','Your message was sent successfully!');
return redirect()->back();
}
}
这是ClientContact邮件类:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class ClientContact extends Mailable
{
use Queueable, SerializesModels;
/**
* @var
*/
public $message;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($message)
{
$this->message = $message;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this
->from(config('mail.from.address'))
->markdown('emails.client.contact', ['message' => $this->message]);
}
}
这是我的测试环境,所以我通过Mailtrap.io捕获出站邮件,并将队列设置为同步。我已经尝试删除Queueable trait,但是由于它根本没有排队,所以这并没有改变任何事情。我还尝试将其放入队列中,当队列最终处理电子邮件时,我会再次收到两封发送的电子邮件。
有什么想法吗?
Route::post('contact-form', 'ContactController@send')->name('contact.form');
- Azeame