Here's my relevant .env:
MAIL_MAILER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
MAILGUN_DOMAIN=https://api.mailgun.net/v3/mail.example.com
MAILGUN_SECRET=fb...a1
Note: I use example.com as an example above, but I've put my actual domain name there. I do not get any errors from the Laravel app, and I do not see anything in the logs on the Mailgun dashboard. My domain is verified. fb...a1 is also the redacted API code, I of course use my full API code I get from the mailgun dashboard.
config/mail.php:
<?php
return [
'default' => env('MAIL_MAILER', 'mailgun'),
'mailers' => [
'mailgun' => [
'transport' => 'mailgun',
],
],
];
config/services.php:
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
],
In my controller I have:
$email = $validated['email']; // I've verified this is my actual email
Mail::to($email)->send(new OrderCreated());
app/Mail/OrderCreated.php:
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class OrderCreated extends Mailable
{
use Queueable, SerializesModels;
public function __construct()
{
//
}
public function build()
{
return $this
->from('no-reply@example.com')
->markdown('emails.order-created');
}
}
And finally, resources/views/emails/order-created.blade.php:
@component('mail::message')
# Order Confirmation
This email is test.
@endcomponent
I'm using Laravel 8.14.0 and Valet 2.13.0, so I'm testing it locally with an https://my-app.test domain. The app is using InertiaJS, in case that makes any difference. The controller code runs without error, but I see no logs on my mailgun dashboard and the email never arrives in my inbox. I have no idea what's wrong or how to debug this.
UPDATE:
I've noticed if I set MAILGUN_DOMAIN and MAILGUN_SECRET to null, I get the same behaviour as above. If I set MAILGUN_DOMAIN to a nonsense value like abcd I get the following error:
GuzzleHttp\Exception\ClientException
Client error: `POST https://api.mailgun.net/v3/abcd/messages.mime` resulted in a `401 UNAUTHORIZED` response: Forbidden
And if I set MAILGUN_SECRET to abcd it works as originally described (no error, but also no email).