PHP code example of orboto / mail
1. Go to this page and download the library: Download orboto/mail library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
orboto / mail example snippets
use Orboto\Mail\OrbotoMail;
$mail = new OrbotoMail(['apiKey' => $_ENV['OMS_API_KEY']]);
$result = $mail->send([
'from' => '[email protected] ',
'to' => '[email protected] ',
'subject' => 'Welcome',
'html' => '<h1>Welcome!</h1>',
]);
echo $result->messageId; // server-issued message id
echo $result->status; // 'queued' at success-time
echo $result->remainingQuota->percentUsed; // 0.0 .. 1.x
$result = $mail->send([
'from' => '[email protected] ',
'to' => '[email protected] ',
'cc' => ['[email protected] ', '[email protected] '], // visible to all (max 50)
'bcc' => ['[email protected] '], // envelope-only (max 50)
'subject' => 'Quarterly report',
'html' => '<p>See attached.</p>',
]);
$result = $mail->send([
'from' => '[email protected] ',
'to' => '[email protected] ',
'subject' => 'Your invoice',
'html' => '<p>Find your invoice attached.</p>',
'attachments' => [
[
'filename' => 'invoice-2026-06.pdf',
'content' => base64_encode(file_get_contents('/tmp/invoice.pdf')),
'contentType' => 'application/pdf',
],
],
]);
$batch = $mail->sendBatch([
'messages' => [
['from' => '[email protected] ', 'to' => '[email protected] ', 'subject' => 'Hi 1', 'text' => 'Hello 1'],
['from' => '[email protected] ', 'to' => '[email protected] ', 'subject' => 'Hi 2', 'text' => 'Hello 2'],
],
]);
foreach ($batch->results as $item) {
if (!$item->ok) {
error_log("Send #{$item->index} failed: {$item->reason}");
}
}
echo "{$batch->summary->queued} queued, {$batch->summary->suppressed} suppressed.";
$tpl = $mail->templates->create([
'name' => 'welcome',
'subject' => 'Welcome to {{company}}',
'bodyHtml' => '<p>Hi {{name}}!</p>',
'variablesSchema' => [
'type' => 'object',
'[email protected] ',
'variables' => ['name' => 'Ada', 'company' => 'ACME'],
]);
use Orboto\Mail\Dto\QuotaState;
use Orboto\Mail\Dto\ConnectionRevokedEvent;
$mail->on('quota-warning', fn (QuotaState $q) => error_log("80%: {$q->current}/{$q->total}"));
$mail->on('quota-low', fn (QuotaState $q) => error_log("95%: {$q->current}/{$q->total}"));
$mail->on('quota-exhausted', fn (QuotaState $q) => error_log("100%: tier cap hit"));
$mail->on('connection-revoked', fn (ConnectionRevokedEvent $e) => error_log("disabled: {$e->message}"));
use Orboto\Mail\Exception\OrbotoMailException;
use Orboto\Mail\Exception\QuotaExhaustedException;
use Orboto\Mail\Exception\PaymentRequiredException;
use Orboto\Mail\Exception\WalletUnavailableException;
use Orboto\Mail\Exception\SuppressedRecipientException;
use Orboto\Mail\Exception\ConnectionRevokedException;
try {
$mail->send([...]);
} catch (PaymentRequiredException $e) {
// Monthly quota used up + wallet balance too low - prompt a top-up
} catch (WalletUnavailableException $e) {
// Transient billing outage; send NOT dispatched - retry shortly
} catch (QuotaExhaustedException $e) {
// Render "upgrade your plan" - $e->getRemainingQuota() has the snapshot
} catch (SuppressedRecipientException $e) {
// Skip + log - recipient on suppression list
} catch (ConnectionRevokedException $e) {
// Disable the integration UX
} catch (OrbotoMailException $e) {
// Generic fallback
if ($e->isRetryable()) { /* server-side transient */ }
}
$mail = new OrbotoMail([
'apiKey' => 'oms_live_xxx', // or set OMS_API_KEY env var
'baseUrl' => 'https://mail.orboto.io/api', // default
'timeout' => 10.0, // seconds per request
'maxRetries' => 3, // transient-error retry budget
'httpClient' => $myPsr18Client, // override the auto-discovered HTTP client
'requestFactory' => $myPsr17RequestFactory,
'streamFactory' => $myPsr17StreamFactory,
]);
use Orboto\Mail\Laravel\OrbotoMailFacade as OrbotoMail;
OrbotoMail::send([
'from' => config('mail.from.address'),
'to' => $user->email,
'subject' => 'Welcome',
'html' => view('mail.welcome', ['user' => $user])->render(),
]);
use Orboto\Mail\Laravel\OrbotoMailChannel;
class Welcome extends Notification
{
public function via($notifiable): array
{
return [OrbotoMailChannel::class];
}
public function toOrbotoMail($notifiable): array
{
return [
'from' => '[email protected] ',
'to' => $notifiable->email,
'subject' => 'Welcome to ACME',
'html' => view('mail.welcome', ['user' => $notifiable])->render(),
];
}
}
bash
php artisan vendor:publish --tag=orboto-mail-config