Install the package via Composer:
composer require bertoost/elasticemail-mailer
Publish the config file (if needed) for customization:
php artisan vendor:publish --provider="Bertoost\ElasticEmail\ElasticEmailServiceProvider"
Register the mailer in config/mail.php under the mailers array:
'elasticemail' => [
'transport' => 'elasticemail',
],
Use the mailer in your application by injecting ElasticEmailMailer or using the Mail facade:
use Illuminate\Support\Facades\Mail;
Mail::mailer('elasticemail')->send(new YourMailClass());
Configure the ElasticEmail API key in .env:
ELASTICEMAIL_API_KEY=your_api_key_here
Send emails via the Mail facade or directly:
Mail::to('recipient@example.com')->send(new YourMailClass());
Or using the mailer directly:
$mailer = app('mailer.elasticemail');
$mailer->send(new YourMailClass());
Ensure Symfony's HttpClient is installed (if not auto-resolved):
composer require symfony/http-client
The package now supports Symfony's HttpClient integration for better HTTP handling. No additional config is required if using Laravel's default HTTP client.
The package now fully supports PHP 8.4. No changes are required for existing projects, but ensure your Laravel version is compatible (Laravel 10+ recommended).
If you encounter issues with Symfony's HttpClient (e.g., timeouts or malformed responses), explicitly bind the client in your AppServiceProvider:
use Symfony\Component\HttpClient\HttpClient;
public function register()
{
$this->app->singleton(\Symfony\Contracts\HttpClient\HttpClientInterface::class, function () {
return HttpClient::create();
});
}
Enable verbose logging for ElasticEmail API calls by setting:
ELASTICEMAIL_LOG_LEVEL=debug
Check logs in storage/logs/laravel.log for detailed API responses.
Never hardcode API keys in your codebase. Use Laravel's .env file and restrict file permissions:
chmod 600 .env
Extend the mailer behavior by binding your own ElasticEmailClient implementation:
$this->app->bind(\Bertoost\ElasticEmail\Contracts\ElasticEmailClient::class, function () {
return new YourCustomElasticEmailClient();
});
If upgrading from PHP <8.4, ensure your codebase uses type-safe methods (e.g., array_key_first instead of reset). The package handles its own deprecations, but dependent code may need updates.
How can I help you explore Laravel packages today?