LaravelPackages.net
Acme Inc.
Toggle sidebar
emailit/emailit-laravel

Laravel integration for the Emailit Email API

4.328
4
v2.0.2
About emailit/emailit-laravel

emailit/emailit-laravel is a Laravel package for laravel integration for the emailit email api. It currently has 4 GitHub stars and 4.328 downloads on Packagist (latest version v2.0.2). Install it with composer require emailit/emailit-laravel. Discover more Laravel packages by emailit or browse all Laravel packages to compare alternatives.

Last updated

Emailit Laravel

Tests Packagist Version License

Laravel integration for the Emailit Email API. Provides a mail transport, a Facade, and full access to the Emailit PHP SDK.

Requirements

  • PHP 8.1+
  • Laravel 10, 11, or 12

Installation

composer require emailit/emailit-laravel

The package auto-discovers its service provider — no manual registration needed.

Configuration

Add your API key to .env:

EMAILIT_API_KEY=your_api_key

Set Emailit as your mail transport in .env:

MAIL_MAILER=emailit

Add the emailit mailer to your config/mail.php mailers array:

'mailers' => [
    // ...

    'emailit' => [
        'transport' => 'emailit',
    ],
],

Publish Config (optional)

php artisan vendor:publish --tag=emailit-config

This publishes config/emailit.php where you can customize the API base URL if needed.

Usage

Once configured as your mail transport, all of Laravel's mail features work out of the box:

use Illuminate\Support\Facades\Mail;
use App\Mail\WelcomeEmail;

Mail::to('[email protected]')->send(new WelcomeEmail($user));

With a Mailable:

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 WelcomeEmail extends Mailable
{
    use Queueable, SerializesModels;

    public function __construct(
        public readonly User $user,
    ) {}

    public function envelope(): Envelope
    {
        return new Envelope(
            subject: 'Welcome to Our App',
        );
    }

    public function content(): Content
    {
        return new Content(
            view: 'emails.welcome',
        );
    }
}

Using the Facade

The Emailit facade gives you direct access to the full Emailit PHP SDK:

use Emailit\Laravel\Facades\Emailit;

// Send an email via the API directly
$email = Emailit::emails()->send([
    'from'    => '[email protected]',
    'to'      => ['[email protected]'],
    'subject' => 'Hello from Emailit',
    'html'    => '<h1>Welcome!</h1>',
]);

echo $email->id;
echo $email->status;

Send with a Template

use Emailit\Laravel\Facades\Emailit;

$email = Emailit::emails()->send([
    'from'      => '[email protected]',
    'to'        => '[email protected]',
    'template'  => 'welcome_email',
    'variables' => [
        'name'    => 'John Doe',
        'company' => 'Acme Inc',
    ],
]);

Manage Domains

use Emailit\Laravel\Facades\Emailit;

$domain = Emailit::domains()->create(['name' => 'example.com']);
$domains = Emailit::domains()->list();

Manage Contacts

use Emailit\Laravel\Facades\Emailit;

$contact = Emailit::contacts()->create([
    'email' => '[email protected]',
    'first_name' => 'John',
]);

$contacts = Emailit::contacts()->list();

Verify Email Addresses

use Emailit\Laravel\Facades\Emailit;

$result = Emailit::emailVerifications()->verify([
    'email' => '[email protected]',
]);

echo $result->status; // valid
echo $result->risk;   // low

All Available Services

The Facade exposes every service from the PHP SDK:

| Service | Property | Description | |---------|----------|-------------| | Emails | Emailit::emails() | Send, list, get, cancel, retry emails | | Domains | Emailit::domains() | Create, verify, list, manage sending domains | | API Keys | Emailit::apiKeys() | Create, list, manage API keys | | Audiences | Emailit::audiences() | Create, list, manage audiences | | Subscribers | Emailit::subscribers() | Add, list, manage subscribers | | Templates | Emailit::templates() | Create, list, publish email templates | | Suppressions | Emailit::suppressions() | Create, list, manage suppressed addresses | | Email Verifications | Emailit::emailVerifications() | Verify email addresses | | Email Verification Lists | Emailit::emailVerificationLists() | Bulk email verification | | Webhooks | Emailit::webhooks() | Create, list, manage webhooks | | Contacts | Emailit::contacts() | Create, list, manage contacts | | Events | Emailit::events() | List and retrieve events |

Error Handling

use Emailit\Exceptions\AuthenticationException;
use Emailit\Exceptions\RateLimitException;
use Emailit\Exceptions\ApiErrorException;
use Emailit\Laravel\Facades\Emailit;

try {
    Emailit::emails()->send([...]);
} catch (AuthenticationException $e) {
    // Invalid API key (401)
} catch (RateLimitException $e) {
    // Too many requests (429)
} catch (ApiErrorException $e) {
    // Any other API error
    echo $e->getHttpStatus();
}

Dependency Injection

You can also inject the client directly instead of using the Facade:

use Emailit\EmailitClient;

class EmailController extends Controller
{
    public function send(EmailitClient $emailit)
    {
        $email = $emailit->emails()->send([
            'from'    => '[email protected]',
            'to'      => ['[email protected]'],
            'subject' => 'Hello',
            'html'    => '<p>Hi there!</p>',
        ]);

        return response()->json(['id' => $email->id]);
    }
}

License

MIT — see LICENSE for details.

Comments