Installation
composer require atm/mailbundle
Add to config/app.php under providers:
Atm\MailBundle\MailBundle::class,
Publish the config:
php artisan vendor:publish --provider="Atm\MailBundle\MailBundle" --tag=config
First Use Case Send a basic email via a service container:
$mailer = $this->container->get('atm_mail.mailer');
$mailer->send([
'to' => '[email protected]',
'subject' => 'Welcome!',
'body' => 'Hello, welcome to our platform!',
'template' => 'emails.welcome' // Optional: Blade template path
]);
Key Config
Check config/atm_mail.php for:
from, reply_to).Template-Based Emails
Store reusable templates in resources/views/emails/ (Blade or PHP).
$mailer->send([
'template' => 'emails.invoice',
'data' => ['amount' => 100, 'user' => $user]
]);
Attachments & Embeds
$mailer->send([
'attachments' => ['/path/to/file.pdf'],
'embeds' => ['/path/to/image.png' => 'cid:image1']
]);
Queueing Emails
Configure atm_mail.php to use queue:mail driver:
'mailer' => [
'driver' => 'queue',
'queue' => 'mail'
],
Dispatch jobs via:
$mailer->queue($emailData);
Event-Based Sending
Listen for events (e.g., user.registered) and trigger emails:
Event::listen('user.registered', function ($user) {
$mailer = app('atm_mail.mailer');
$mailer->send(['to' => $user->email, 'template' => 'emails.welcome']);
});
Custom Mailers Extend the base mailer for domain-specific logic:
use Atm\MailBundle\Mailer\MailerInterface;
class CustomMailer implements MailerInterface {
public function send(array $data) {
// Custom logic (e.g., logging, analytics)
$defaultMailer->send($data);
}
}
Bind in AppServiceProvider:
$this->app->bind(MailerInterface::class, CustomMailer::class);
$user->notify(new WelcomeEmail($mailer));
$this->app->instance('atm_mail.mailer', Mockery::mock('Atm\MailBundle\Mailer\MailerInterface'));
atm_mail.php:
'debug' => env('MAIL_DEBUG', false),
Template Paths
resources/views/layouts/email.blade.php).ob_start()/ob_get_clean().Queue Stuck Jobs
failed_jobs table if emails aren’t sending.php artisan queue:retry all
Attachment Permissions
Circular Dependencies
Enable Debug Mode:
'debug' => true, // in atm_mail.php
Logs will appear in storage/logs/atm_mail.log.
Check Raw Output:
$mailer->send(['debug' => true, ...]);
Returns the raw email string for inspection.
Custom Transport
Override the transport layer by binding Atm\MailBundle\Transport\TransportInterface:
$this->app->bind(TransportInterface::class, CustomTransport::class);
Pre/Post-Send Hooks
Use the atm.mail.sending and atm.mail.sent events:
Event::listen('atm.mail.sending', function ($event) {
// Modify $event->data before sending
});
Dynamic Templates Fetch templates dynamically (e.g., from a database):
$template = Template::find($id)->content;
$mailer->send(['body' => $template, 'data' => $vars]);
atm_mail.php or per-email:
$mailer->send(['from' => '[email protected]', ...]);
atm_mail.php:
'rate_limiting' => [
'enabled' => true,
'max_emails' => 100,
'period' => 'hour',
],
How can I help you explore Laravel packages today?