Looking to hire Laravel developers? Try LaraJobs

laravel-vodafone-sms maintained by biztecheg

Description
Laravel integration for the Vodafone Egypt E'len SMS API (web2sms): several accounts and sender names, OTP and campaign sends, a notification channel and a test fake. Unofficial.
Author
Last update
2026/11/29 12:13 (dev-main)
License
Links
Downloads
3

Comments
comments powered by Disqus

Laravel Vodafone SMS

Laravel integration for the Vodafone Egypt E'len SMS API (web2sms): send OTPs and notifications, run campaigns, use several accounts and sender names, and test it all without sending a single SMS.

Unofficial. This package is not made, endorsed or supported by Vodafone or Edafa.

Features

  • Several accounts, several senders. Each account has its own credentials and its own list of sender names, with aliases (otp, promo) so app code asks for a purpose, not a brand string. Once the list is filled in, a sender the account does not have is refused before anything is sent (an empty list allows any name; vodafone-sms:doctor warns about it). Accounts can also come from your database (one per tenant).
  • Notification and campaign interfaces, kept apart. Vodafone suspends accounts that send campaign traffic through the notification interface. send() refuses more than a handful of messages; campaign() uses the campaign interface and splits any list into requests of 1000.
  • The SecureHash done right. It is verified against Vodafone's own worked examples, which only work with the secret used as-is (the document's text says otherwise; both modes are supported).
  • Numbers normalized. Every Egyptian format (010…, +2010…, 002010…, 2010…, 10…) becomes 2010XXXXXXXX. Spaces, dashes and Arabic-Indic digits (٠١٠…) are accepted. Invalid numbers are refused, or dropped and reported in a campaign.
  • Cost guard. Segment counting follows GSM 03.38 (7-bit: 160/153; Unicode, so any Arabic: 70/67). A message over max_segments is refused.
  • Laravel notification channel, a test fake with assertions, and a log driver for machines that are not on Vodafone's IP whitelist.
  • Events for accepted requests, rejected requests and account suspension.
  • No secrets leak. Logs carry metadata only (never numbers, texts or passwords); an invalid-number exception shows the number masked (2010******78). Requests go through a private HTTP client that Telescope and similar tools don't record. Credentials are redacted from dumps.
  • vodafone-sms:doctor checks the configuration. vodafone-sms:send sends a test SMS or previews it.

Requirements

  • PHP 8.2+ with dom, mbstring and xmlwriter
  • Laravel 10.48+, 11, 12 or 13
  • An E'len SMS API account. Vodafone only accepts requests from whitelisted server IPs, over TLS 1.2+

Installation

composer require biztecheg/laravel-vodafone-sms
php artisan vendor:publish --tag=vodafone-sms-config   # optional

.env for a single account:

VODAFONE_SMS_ACCOUNT_ID=123456789
VODAFONE_SMS_PASSWORD=...
VODAFONE_SMS_SECRET=...
VODAFONE_SMS_SENDERS=MyBrand,MyBrandOffers
VODAFONE_SMS_SENDER=MyBrand

Then check it:

php artisan vodafone-sms:doctor
php artisan vodafone-sms:send 01012345678 "Test" --dry-run   # validates and previews, sends nothing
php artisan vodafone-sms:send 01012345678 "Test"             # from a whitelisted server

On a development machine set VODAFONE_SMS_DRIVER=log: messages are written to the log instead of being sent.

Sending

use BiztechEG\VodafoneSms\Facades\VodafoneSms;

// One message, notification interface (OTP, alerts, receipts)
$result = VodafoneSms::send('01012345678', 'Your code is 4821');
$result->successful();          // accepted, and the message was SUBMITTED

// With a reference (sent as ExternalTrxId; shows in Vodafone's reports)
VodafoneSms::send('01012345678', 'Your code is 4821', reference: (string) $log->id);

// Another sender (an alias or a sender name) or another account
VodafoneSms::sender('promo')->send('01012345678', '...');
VodafoneSms::account('marketing')->sender('offers')->send('01012345678', '...');

// Different messages in one notification request
use BiztechEG\VodafoneSms\Data\SmsMessage;

VodafoneSms::sendMany([
    SmsMessage::make('01012345678', 'Code 1111'),
    SmsMessage::make('01112345678', 'Code 2222'),
]);

Campaigns

$result = VodafoneSms::campaign($numbers, 'Our sale ends tonight', reference: 'sale-2026-12');

$result->submittedCount();      // messages Vodafone queued
$result->invalid;               // [['message' => SmsMessage, 'reason' => '...'], ...] dropped before sending
$result->duplicates;            // repeats dropped (same number, sender and text)
$result->failedChunks();        // requests that failed or were skipped
$result->throw();               // rethrow the first error, if you prefer exceptions

A campaign never throws for one bad chunk. The rest is skipped and reported after an authentication or account error, a SUSPENDED answer or a chunk the rate limit refused entirely (every later chunk would fail the same way), or after a network error (it is unknown whether the chunk went out). $result->unsent() lists the messages that certainly did not go out (skipped, refused, or FAILED_TO_SUBMITTED), ready to send again later.

Results and errors

What happened What you get
A message is invalid (number, empty or too long text, unknown sender) InvalidMessageException (SenderNotAllowedException for a sender); nothing sent
A setting is missing (secret, default sender, unknown account) ConfigurationException; nothing sent
Vodafone refused the whole request RequestRejectedException with errorCode() (an ErrorCode enum with description(), hint() and category()). Bad credentials, Secure Hash or IP give its subclass AuthenticationException
No usable answer (network, timeout, HTTP error, not XML) TransportException; the message may have been sent. It is not chained, and its message names only the client's exception class and the libcurl error (cURL error 28 (Timeout was reached)), never the client's own words, which may quote the request. Other errors (a bug, Http::preventStrayRequests() in a test) are thrown as they are
Vodafone answered a status this version does not know, with no per-message status and no error code UnknownOutcomeException, a TransportException: the message may have been sent
Vodafone accepted the request a SubmitResult: messages holds each message's SmsStatus (Submitted, FailedToSubmit (rate limit, retry later), Suspended, Invalid)

A request is never retried by the package: after a timeout, a retry could deliver the SMS twice. Retry in your queue job when a duplicate is acceptable (an OTP usually is).

SUBMITTED means queued at Vodafone. The API has no delivery reports.

Several accounts and senders

// config/vodafone-sms.php
'default' => 'main',

'accounts' => [
    'main' => [
        'account_id' => env('VODAFONE_SMS_ACCOUNT_ID'),
        'password' => env('VODAFONE_SMS_PASSWORD'),
        'secret' => env('VODAFONE_SMS_SECRET'),
        'senders' => ['otp' => 'MyBrand', 'promo' => 'MyBrandOffers'],
        'default_sender' => 'otp',
    ],
    'marketing' => [
        'account_id' => env('VODAFONE_SMS_MARKETING_ACCOUNT_ID'),
        'password' => env('VODAFONE_SMS_MARKETING_PASSWORD'),
        'secret' => env('VODAFONE_SMS_MARKETING_SECRET'),
        'senders' => ['MyBrandNews'],          // a single sender is the default
        'max_segments' => 3,                   // any shared default can be overridden per account
    ],
],

Accounts that live elsewhere (one per tenant, say):

VodafoneSms::resolveAccountsUsing(fn (string $name) => Tenant::where('sms_account', $name)->first()?->smsConfig());

VodafoneSms::account('tenant-42')->send($phone, $text);

// or build one on the spot
VodafoneSms::using(['account_id' => '...', 'password' => '...', 'secret' => '...', 'senders' => ['Brand']])
    ->send($phone, $text);

The resolver runs on every lookup; cache on your side if it queries a database. A gateway you keep in a variable keeps its account as it was (credentials, senders), so ask for a new one after a change. The package options and the log channel are read on every send.

Notification channel

use BiztechEG\VodafoneSms\Notifications\VodafoneSmsMessage;

class LoginCode extends Notification
{
    public function via(object $notifiable): array
    {
        return ['vodafone-sms'];
    }

    public function toVodafoneSms(object $notifiable): VodafoneSmsMessage|string
    {
        return VodafoneSmsMessage::create("Your code is {$this->code}")
            ->sender('otp')            // optional
            ->account('main')          // optional
            ->reference($this->id);    // optional
    }
}

// On the notifiable:
public function routeNotificationForVodafoneSms(): ?string
{
    return $this->phone;
}

// Or on demand:
Notification::route('vodafone-sms', '01012345678')->notify(new LoginCode('4821'));

Each notification is one notification-interface request. To message many users at once, use campaign().

Unlike send(), the channel throws a MessageNotSubmittedException when Vodafone accepts the request but does not submit the message (FAILED_TO_SUBMITTED, SUSPENDED, INVALID). A queued notification therefore fails and is retried instead of counting as sent; $e->retryable() is true for FAILED_TO_SUBMITTED (a rate limit).

Events

Event When
Events\SmsSubmitted Vodafone accepted a request (check each message's status)
Events\SmsRequestRejected Vodafone refused a request
Events\AccountSuspended A message came back SUSPENDED: alert someone

A listener that throws does not fail the send (the SMS has already gone out); its exception is reported to your exception handler. A log channel or exception handler that throws in turn, or a log channel that cannot be built, is ignored for the same reason; vodafone-sms:doctor reports a log_channel that does not exist or cannot be built (a broken driver, a throwing tap, a bad stack member).

Each event carries $event->result (a SubmitResult with the account name, endpoint, submission and statuses). A listener in the same process sees the SMS texts. A SubmitResult blanks every text when it is serialized, so an OTP never sits in the jobs table, a cache or a session (a queued listener gets it without texts), and json_encode() of a result or a CampaignResult (what Telescope and Monolog record) gives metadata only, with masked numbers. A serialized CampaignResult keeps each chunk's messages, so unsent() still works after a queue.

Do not queue or cache the exceptions themselves. Like any PHP exception, their trace holds every call's arguments, the SMS text included, unless zend.exception_ignore_args is On (the php.ini-production default). Queue $e->result instead: it carries no text. The package's own messages, log lines and JSON carry no text or full number either. They quote a status this version knows and an error code it knows (any other code is unknown), never a raw value from Vodafone's answer, which could be anything: read $result->rawStatus and $result->rawCode for those. A custom transport's TransportException says whatever that transport wrote, so CampaignResult's JSON gives each chunk error's class and codes, not its message.

Testing

use BiztechEG\VodafoneSms\Enums\Endpoint;
use BiztechEG\VodafoneSms\Enums\ErrorCode;
use BiztechEG\VodafoneSms\Enums\SmsStatus;
use BiztechEG\VodafoneSms\Exceptions\TransportException;
use BiztechEG\VodafoneSms\Testing\SentSms;

$sms = VodafoneSms::fake();

// ... code under test ...

$sms->assertSentTo('01012345678', fn (SentSms $s) => str_contains($s->text, '4821'));
$sms->assertSentVia(Endpoint::Notification, 1);
$sms->assertNothingSent();

// Script Vodafone's answers
$sms->rejectNext(ErrorCode::WrongPassword);
$sms->nextStatuses(SmsStatus::FailedToSubmit);
$sms->throwNext(new TransportException('timeout'));

The fake still validates numbers, texts and senders, and fires the events. "Sent" means SUBMITTED. Every message of a request that would have gone to Vodafone is in $sms->attempted(): those answered with another status (scripted with nextStatuses()) and those in a request refused or failed as a whole (rejectNext(), throwNext(); $accepted is false). None of them counts in the assertions. A request that fails checkCredentials is not an attempt; it would not have left the server.

The fake needs no credentials, so CI needs no secrets. VodafoneSms::fake(checkCredentials: true) makes a missing account_id, password or secret fail as it would in production; vodafone-sms:doctor checks the real ones on the server.

Helpers

VodafoneSms::analyze('كود التفعيل 4821');   // TextInfo: encoding, length, segments, remaining()
VodafoneSms::normalize('٠١٠١٢٣٤٥٦٧٨');      // "201012345678"

Configuration reference

Key Default Meaning
driver vodafone log writes messages to the log instead of sending them
default main Account used when none is named
defaults.key_mode raw raw = secret used as-is (matches Vodafone's examples); hex = hex-decoded. Switch if Vodafone answers 9021
defaults.base_url https://e3len.vodafone.com.eg/web2sms/sms/submit /Notification is appended for notification sends
defaults.allow_international false Accept 00…/+… numbers
defaults.max_segments 6 Refuse longer messages; null = no limit
notification.max_messages 10 Most messages per notification request
campaign.chunk_size 1000 Messages per campaign request (Vodafone's maximum)
campaign.dedupe true Drop repeated number+sender+text in a campaign
auto_reference false Give every request a ULID ExternalTrxId
log_channel null Metadata-only log channel

Error codes

All codes from Vodafone's interface document (V5.0) are in BiztechEG\VodafoneSms\Enums\ErrorCode, each with Vodafone's description, a hint where useful, and a category: Authentication (credentials, Secure Hash, IP), Account (sender, interface, eligibility, quota), InvalidRequest or Server.

License

MIT. See LICENSE.