LeadMail SDK for Laravel
Laravel package for sending emails and verifying email addresses through the leadMail service.
Requirements
- PHP 8.2+
- Laravel 11 or 12
Installation
composer require leadm/leadmail
Publish the config file:
php artisan vendor:publish --provider="LeadM\LeadMail\LeadMailServiceProvider"
Configuration
Add these to your .env:
LEADMAIL_URL=https://mail.leadmagnet.dev
LEADMAIL_TOKEN=lm_your_api_token_here
Optional settings:
LEADMAIL_TIMEOUT=30
LEADMAIL_VERIFY_SSL=true
LEADMAIL_AUTO_TENANT=true
Usage
Send Emails via Mail Driver
Set leadmail as your mail driver in .env:
MAIL_MAILER=leadmail
Then use Laravel's Mail facade as usual:
Mail::to('user@example.com')->send(new WelcomeMail());
Send Emails via API
LeadMail::sendEmail([
'from' => ['email' => 'hello@yourdomain.com', 'name' => 'Your App'],
'to' => [['email' => 'user@example.com', 'name' => 'User']],
'subject' => 'Welcome!',
'html_body' => '<h1>Welcome to our app</h1>',
]);
Verify Email Addresses
$result = LeadMail::verifyEmail('user@example.com');
if ($result['data']['valid']) {
// Email is deliverable
}
Validation Rule
Use the leadmail_verify rule in your form requests:
public function rules(): array
{
return [
'email' => ['required', 'email', 'leadmail_verify'],
];
}
Get Allowed Sender Domains
$domains = LeadMail::getDomains();
// ['yourdomain.com', 'anotherdomain.com']
Multi-Tenancy
If your app uses stancl/tenancy, the SDK automatically includes the current tenant ID in API requests via the X-Tenant-Id header. Disable this with:
LEADMAIL_AUTO_TENANT=false
License
MIT
Languages
PHP
100%