Prerequisites
To get the most out of this guide, you’ll need to:- Create a SendPost Account
- Laravel 9+
- PHP 8.1+
- A Sub-Account API Key from your SendPost dashboard
You can find your API keys in your SendPost Dashboard. Make sure to use your Sub-Account API Key for sending emails.
1. Install Dependencies
composer
The SDK uses Guzzle 7. New Laravel 13 apps ship with Guzzle 8, and
-W lets Composer switch them to Guzzle 7, which Laravel also supports.2. Environment Setup
Add to your.env file:
Laravel uses
MAIL_FROM_ADDRESS and MAIL_FROM_NAME as the default sender for every mailable and notification.3. Create SendPost Mail Driver
Laravel 9+ sends mail through Symfony Mailer, so the driver is a Symfony transport. Createapp/Mail/Drivers/SendPostTransport.php:
PHP
4. Register Mail Driver
Add toapp/Providers/AppServiceProvider.php:
PHP
config/services.php:
PHP
config/mail.php:
PHP
5. Send Your First Email
Using Mail Facade
PHP
Using Mailable Class
Create a mailable:app/Mail/WelcomeEmail.php:
PHP
resources/views/emails/welcome.blade.php:
Blade
PHP
6. Common Use Cases
Password Reset Email
Createapp/Mail/PasswordResetEmail.php:
PHP
resources/views/emails/password-reset.blade.php:
Blade
Order Confirmation Email
Createapp/Mail/OrderConfirmation.php:
PHP
7. Using Notifications
Create a notification:app/Notifications/WelcomeNotification.php:
PHP
PHP
8. Personalization with Custom Fields
Create a custom mailable with personalization:PHP
9. Direct API Usage (Alternative)
Createapp/Services/SendPostService.php:
PHP
PHP
10. Next Steps
Explore more examples and use cases:Laravel Documentation
Learn more about Laravel framework
SendPost PHP SDK
View the official SDK on GitHub
Quickstart Example
View a complete working example on GitHub