Laravel package for our API: SMS and e-mail notifications, domains, DNS and WHOIS

API & DocumentationSDKs, CLI & Libraries·· 88 views· 3 min read

If you have a Laravel application, this package sends SMS notifications through the SMS Center, sends your app's mail through E-mail Center, and works with domains, DNS and WHOIS, all on our API.

What it does

SMS: an 'sms' channel for notifications. Return 'sms' from via() and write a toSms() method.

Mail: a mozout mailer for E-mail Center. Mailables, mail notifications, attachments, Cc and Bcc all work.

The rest of the API: the MozOut facade handles domains, WHOIS, DNS, SMS and E-mail Center, and calls any other operation, for example MozOut::get('/v1/services');.

What you need

Laravel 8 to 12, and PHP 7.4 or newer with cURL. No other packages. And an API key, created in the API Center of My MozOut.

Installing, step by step

1 In your project folder, install the package with composer require mozout/laravel. Laravel finds the service provider and the facade on its own.
2 Add the key to .env: MOZOUT_API_KEY=sandbox_.... That is the only setting you need: the API address is already in the package.
3 Check the key with php artisan mozout:check.
4 To change the error language, the timeout or the default SMS sender, publish the config file with php artisan vendor:publish --tag=mozout-config.

To send your app's mail through E-mail Center, add the mozout mailer to config/mail.php and set MAIL_MAILER=mozout in .env. An SMS to any number goes out like this:

Notification::route('sms', '+14155550123')->notify(new OrderShipped());

The API key and its permissions

SMS notifications need sms:write, and SMS must be active in the SMS Center of the account. Mail needs email_center:write, and the sender (MAIL_FROM_ADDRESS) must be on a sender domain verified in E-mail Center.

When you are ready, create a prod_ key with only the permissions you use. See permissions by area.

Testing without spending

Start with a sandbox_ key: writes are simulated and nothing is charged. MozOut::wasSimulated() tells you whether the last write was only simulated. WHOIS works without a key too.

Good to know

Queues: queued notifications are safe to retry: the same notification never sends the SMS twice.

Retries: POST requests carry an Idempotency-Key, so a retry never registers or sends twice. Requests that get 429, 500, 502 or 503 are retried after a short wait.

Templates: to send with an E-mail Center template, add 'template_id' => 7 to the mailer and use 'variables' for its values.

Errors: every error is a MozOut\Laravel\ApiException. Its hint() tells you what to do, in one sentence.

Help

If the API returns an error you do not understand, open a support ticket and send us what getCorrelationId() returns on the exception, never the key. The code is in the Laravel package repository, under the MIT license.

Ready to send SMS and mail from Laravel?

Download the latest release

SEE ALSO

Getting a Laravel application running

API permissions by area

Creating an API key

The repository on MozOut Git

SDKs and integrations, in the API documentation

RECOMMENDED PRODUCT

Register your .com domain

Secure your company name before someone else registers it. from KSh2,210.00/yr

Search a domain
Was this answer helpful? Your answer helps us improve this article.