Laravel¶
Guide for applications built with Laravel (10.x and 11.x). Mailexam connects as a standard SMTP server — only the configuration in .env changes; sending code (Mail, Mailable, queues) stays the same.
What you need¶
- A Mailexam account and a project with SMTP credentials.
- A Laravel application with the mail module configured (
config/mail.phpby default).
Copy from the welcome email (or dashboard) for your project:
YOUR_LOGIN— SMTP login (for example,xxxxx);YOUR_PASSWORD— SMTP password (a unique pair with the login);- host in the email —
YOUR_LOGIN.mailexam.io(the hostname matches the login).
1. Configuring .env¶
Add or update mail variables:
MAIL_MAILER=smtp
MAIL_HOST=YOUR_LOGIN.mailexam.io
MAIL_PORT=587
MAIL_USERNAME=YOUR_LOGIN
MAIL_PASSWORD=YOUR_PASSWORD
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=noreply@example.test
MAIL_FROM_NAME="${APP_NAME}"
Sender address
MAIL_FROM_ADDRESS can be any test address — the message still goes to Mailexam, not to a real recipient. For consistency in tests, it is convenient to use the *.test domain or @example.com.
Alternative ports¶
Apply the configuration:
In production, after verification you can cache: php artisan config:cache.
2. Checking config/mail.php¶
In a standard Laravel install, config/mail.php already reads variables from .env. Additional changes are usually not required. Make sure the smtp mailer uses env('MAIL_HOST'), env('MAIL_PORT'), and so on.
3. Sending a test email¶
Via Tinker¶
use Illuminate\Support\Facades\Mail;
Mail::raw('Mailexam test from Laravel', function ($message) {
$message->to('user@example.test')
->subject('Laravel + Mailexam');
});
Via Mailable¶
// app/Mail/WelcomeTestMail.php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class WelcomeTestMail extends Mailable
{
use Queueable, SerializesModels;
public function envelope(): Envelope
{
return new Envelope(subject: 'Welcome (test)');
}
public function content(): Content
{
return new Content(view: 'emails.welcome-test');
}
}
use App\Mail\WelcomeTestMail;
use Illuminate\Support\Facades\Mail;
Mail::to('user@example.test')->send(new WelcomeTestMail());
Open the Mailexam dashboard → project → inbox: the message should appear within a few seconds.
4. Local development and CI¶
| Environment | Recommendation |
|---|---|
local |
A separate Mailexam project per developer or a shared team test project |
staging |
Its own Mailexam project, same .env via CI secrets |
| PHPUnit | Either real Mailexam SMTP in integration tests, or MAIL_MAILER=array / log for unit tests without network |
Example variables in GitLab CI (Settings → CI/CD → Variables):
variables:
MAIL_MAILER: smtp
MAIL_HOST: "${MAILEXAM_LOGIN}.mailexam.io"
MAIL_PORT: "587"
MAIL_USERNAME: "${MAILEXAM_LOGIN}"
MAIL_PASSWORD: "${MAILEXAM_PASSWORD}"
MAIL_ENCRYPTION: tls
After sending a message in the pipeline, verify delivery via the Mailexam API.
5. Common issues¶
Connection could not be established
MAIL_HOSTmust beYOUR_LOGIN.mailexam.io— the same login as inMAIL_USERNAME, without ansmtp.prefix.- Take login and password as a pair from the email; do not mix credentials from another project.
- Run
php artisan config:clearafter changing.env.
Message not visible in the dashboard
- Check that you are viewing the inbox of the same project whose credentials are in
.env. - Make sure sending did not go to a queue with an error:
php artisan queue:workand logs instorage/logs/laravel.log.
SSL/TLS errors
- For port 587 use
MAIL_ENCRYPTION=tls, notssl. - Port 465 with
sslis supported, but not recommended for new integrations.