I built a contact form which is sending two emails instead of one. Here's the controller:
<?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();
}
}
Here's the ClientContact Mail Class
<?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]);
}
}
It's my testing environment so I'm capturing outgoing mail through Mailtrap.io and the queue is set to sync. I already tried removing the Queueable trait but that didn't change anything as it's not queuing anyway. I also tried putting it on the Queue, and when the queue finally processes the email I again, get two sent emails.
Any ideas?
It's a mailtrap
issue, and only if you're using the bcc
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With