Skip to content

Scheduling messages

Pass an SmsSchedule in the request’s schedule field. The start must be at least five minutes in the future and must include a time-zone offset.

use DateTimeImmutable;
use Rayo\SmsSdk\Models\SmsRequest;
use Rayo\SmsSdk\Models\SmsSchedule;
$response = $client->sendSms(new SmsRequest(
'MYBRAND',
'Reminder: your appointment is tomorrow at 10:00.',
'306912345678',
null,
'appointment-1001',
true,
false,
true,
SmsSchedule::oneOff(new DateTimeImmutable('+2 hours'))
));
if ($response->isScheduled()) {
$scheduleId = $response->getSmsRequestScheduleId();
}

Use an advanced calendar cron(...) expression or fixed rate(...) interval, plus an IANA time zone:

use DateTimeImmutable;
use Rayo\SmsSdk\Models\SmsSchedule;
$schedule = SmsSchedule::recurring(
'cron(30 9 ? * MON-FRI *)',
'Europe/Athens',
new DateTimeImmutable('2026-12-01T09:30:00+02:00'),
new DateTimeImmutable('2027-03-01T09:30:00+02:00')
);
$response = $client->sendSms([
'fromLabel' => 'MYBRAND',
'toMobileNumber' => '306912345678',
'smsBody' => 'Your weekday update.',
'schedule' => $schedule,
]);

The end date is optional. A recurring schedule without endsAt continues until it is disabled, deleted, or otherwise becomes inactive.

You can provide the schedule as an associative array instead:

$response = $client->sendSms([
'fromLabel' => 'MYBRAND',
'toMobileNumber' => '306912345678',
'smsBody' => 'A fixed-interval update.',
'schedule' => [
'type' => 'recurring',
'expression' => 'rate(2 hours)',
'timezone' => 'Europe/Athens',
'startsAt' => '2026-12-01T09:30:00+02:00',
],
]);
Meaning Expression
Every day at 09:30 cron(30 9 * * ? *)
Every weekday at 09:30 cron(30 9 ? * MON-FRI *)
Monday and Wednesday at 09:30 cron(30 9 ? * MON,WED *)
Day 15 of every month at 09:30 cron(30 9 15 * ? *)
Every two hours rate(2 hours)

cron(...) uses six fields: minute, hour, day-of-month, month, day-of-week, and year. Exactly one of day-of-month and day-of-week must be ?. The time zone controls the wall-clock interpretation, including daylight-saving changes. rate(...) intervals are fixed.

Persist getSmsRequestScheduleId() when the response is scheduled. Scheduled responses contain the schedule ID rather than a server SMS request ID; each occurrence creates its own request when it runs.

Disable a schedule to pause it. While it is disabled, no SMS is sent on its behalf, and it keeps its delivery history. Enable it again to resume:

$disabled = $client->disableSchedule($scheduleId);
echo $disabled->getSmsRequestScheduleState(); // "disabled"
$enabled = $client->enableSchedule($scheduleId);
if ($enabled->isExpired()) {
// The recurring schedule's endsAt passed while it was disabled.
// It will not send again.
}

Both methods return a ScheduleStateChangeResponse. getSmsRequestScheduleState() returns one of:

Constant Value Meaning
ScheduleStateChangeResponse::STATE_ACTIVE active The schedule sends messages
ScheduleStateChangeResponse::STATE_DISABLED disabled The schedule is paused
ScheduleStateChangeResponse::STATE_EXPIRED expired A recurring schedule whose endsAt has passed

isActive(), isDisabled(), and isExpired() test the state. disableSmsRequestSchedule() and enableSmsRequestSchedule() are aliases matching the API operation names.

The API refuses a state change with HTTP status 422, which the SDK throws as a RayoException:

  • Only an active schedule can be disabled, and only a disabled schedule can be enabled.
  • A one-off schedule cannot be enabled after its start time has passed.
  • If your account has to submit company details, they must be confirmed before you can enable a schedule.
$result = $client->deleteSchedule($scheduleId);
if ($result->isSuccess()) {
echo 'Deleted: ' . $result->getSmsRequestScheduleId();
}

deleteSmsRequestSchedule() is an alias matching the API operation name.