Laravel has a first-class mail system built on Symfony Mailer that supports SMTP out of the box. Connecting it to MigoSMTP takes less than 5 minutes — update your .env file with MigoSMTP credentials and you are done. This article covers SMTP configuration, the Email API driver alternative, queue setup, and testing.
Option 1 — SMTP Driver (Recommended for Most Use Cases)
The SMTP driver uses your MigoSMTP SMTP credentials and works with Laravel's built-in mail system, all queuing, all Mailables, and all notification channels.
Step 1 — Add Credentials to .env
# .env
MAIL_MAILER=smtp
MAIL_HOST=smtp.migosmtp.com
MAIL_PORT=587
MAIL_USERNAME=your_smtp_username_from_migosmtp
MAIL_PASSWORD=your_smtp_password_from_migosmtp
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=hello@yourdomain.com
MAIL_FROM_NAME="${APP_NAME}"
.env is listed in your .gitignore file. For production deployments, set these values as server environment variables or through your deployment platform's secrets manager.
Step 2 — Clear Config Cache
php artisan config:clear
Step 3 — Verify config/mail.php
Ensure config/mail.php has the default mailer set to the SMTP driver (it should by default):
// config/mail.php
'default' => env('MAIL_MAILER', 'smtp'),
Step 4 — Send a Test Email via Artisan
php artisan tinker
Mail::raw('Test email from Laravel via MigoSMTP', function($message) {
$message->to('your@email.com')->subject('MigoSMTP Test');
});
Check your inbox for the test email and verify it appears in the MigoSMTP delivery reports.
Option 2 — Email API Driver (Higher Performance)
For high-volume sending or when you want delivery tracking and webhook events per message, use the MigoSMTP REST API directly from Laravel rather than SMTP:
Step 1 — Store API Key in .env
# .env
MIGOSMTP_API_KEY=your_api_key_here
MAIL_FROM_ADDRESS=hello@yourdomain.com
MAIL_FROM_NAME="${APP_NAME}"
Step 2 — Create a Custom Mail Transport
// app/Mail/MigoSmtpTransport.php
namespace AppMail;
use SymfonyComponentMailerSentMessage;
use SymfonyComponentMailerTransportAbstractTransport;
use SymfonyComponentMimeMessageConverter;
use IlluminateSupportFacadesHttp;
class MigoSmtpTransport extends AbstractTransport
{
public function __construct(private string $apiKey) {
parent::__construct();
}
protected function doSend(SentMessage $message): void
{
$email = MessageConverter::toEmail($message->getOriginalMessage());
$payload = [
'from' => $email->getFrom()[0]->getAddress(),
'to' => $email->getTo()[0]->getAddress(),
'subject' => $email->getSubject(),
'html' => $email->getHtmlBody(),
'text' => $email->getTextBody(),
];
Http::withToken($this->apiKey)
->post('https://api.migosmtp.com/v1/email/send', $payload)
->throw();
}
public function __toString(): string { return 'migosmtp'; }
}
Step 3 — Register the Transport in AppServiceProvider
// app/Providers/AppServiceProvider.php
use AppMailMigoSmtpTransport;
use IlluminateSupportFacadesMail;
public function boot(): void
{
Mail::extend('migosmtp', function () {
return new MigoSmtpTransport(config('services.migosmtp.key'));
});
}
Step 4 — Set Mailer in .env
MAIL_MAILER=migosmtp
Using Laravel Queues for Email
For production applications, always queue emails so they are processed asynchronously and do not slow down HTTP responses:
// Send immediately (not recommended for production) Mail::to($user)->send(new WelcomeMail($user)); // Queue for background processing (recommended) Mail::to($user)->queue(new WelcomeMail($user)); // Schedule for a specific time Mail::to($user)->later(now()->addMinutes(5), new WelcomeMail($user));
Ensure a queue worker is running to process queued emails:
php artisan queue:work --queue=default --tries=3
Laravel Notification Channel
MigoSMTP works with Laravel's built-in mail notification channel:
// app/Notifications/OrderShipped.php
use IlluminateNotificationsMessagesMailMessage;
public function toMail($notifiable): MailMessage
{
return (new MailMessage)
->subject('Your order has shipped')
->greeting('Hello ' . $notifiable->name . '!')
->line('Your order #' . $this->order->id . ' has been shipped.')
->action('Track Your Order', url('/orders/' . $this->order->id))
->line('Thank you for your purchase!');
}
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| Connection refused on port 587 | Outbound port blocked by server or hosting provider | Use port 465 with MAIL_ENCRYPTION=ssl; or ask host to open port 587 |
| Expected response code 250 but got 535 | Authentication failed — wrong username or password | Re-copy credentials from MigoSMTP SMTP Accounts page; run php artisan config:clear |
| Emails sending in local but not in production | .env not loaded; using cached config with old values | Run php artisan config:clear && php artisan cache:clear on production |
| Queued emails not being sent | Queue worker not running | Start worker: php artisan queue:work; use Supervisor for persistent workers in production |
| SSL certificate error | Outdated CA bundle on server | Update server CA certificates: sudo apt-get update && sudo apt-get install ca-certificates |