Adds a driver for the SocketLabs Injection API to Laravel's email services.
- PHP 7.3 or greater.
- A SocketLabs account with a server ID and API key.
Install the package with composer.
composer require rhysnhall/laravel-socketlabs-driver
Once you register and set up an account with SocketLabs, you'll be presented with a server ID and an API key. Add both of these to your ENV file.
SOCKET_LABS_API_KEY={your_key}
SOCKET_LABS_SERVER_ID={server_id}
Next, add the SocketLabs credentials to your config\services.php
config file.
'socketlabs' => [
'key' => env('SOCKET_LABS_API_KEY'),
'id' => env('SOCKET_LABS_SERVER_ID')
]
Add the SocketLabs service provider to the config\app.php
config file.
'providers' => [
...
Rhysnhall\LaravelSocketLabsDriver\SocketLabsServiceProvider::class
]
The last step is to add the SocketLabs driver to the config\mail.php
config file.
'mailers' => [
...
'socketlabs' => [
'transport' => 'socketlabs'
]
]
You may also want to set SocketLabs as your default mailer, depending on your setup. You'll need to update the MAIL_MAILER
variable in your ENV file.
MAIL_MAILER=socketlabs
You can directly add your config variables to the config\mail.php
config file or create a new config file to hold these.
config\mail.php
'mailers' => [
...
'socketlabs' => [
'transport' => 'socketlabs',
'retries' => 2,
'timeout' => 120,
'proxy_url' => 'https://example'
]
]
config\socketlabs.php
<?php
return [
'retries' => 2,
'timeout' => 120,
'proxy_url' => 'https://example'
];
Use the driver as you would any other email driver.
App\Mail\Test
class Test extends Mailable {
public function build()
{
return $this->from('[email protected]')
->view('emails.html.test')
->text('emails.plain.test')
->attach(storage_path('test_image.png'));
}
}
Mail::to('[email protected]')->send(new \App\Mail\Test);
Help improve this package by contributing.
Before opening a pull request, please discuss the proposed changes via Github issue or email.
This project is licensed under the MIT License - see the LICENSE file for details