How to send SMS Messages

Version: 5.0
Edit this page

Warning: You are browsing the documentation for Symfony 5.0, which is no longer maintained.

Read the updated version of this page for Symfony 5.3 (the current stable version).

How to send SMS Messages

5.0

The Notifier component was introduced in Symfony 5.0 as an experimental feature.

The TexterInterface class allows you to send SMS messages:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// src/Controller/SecurityController.php
namespace App\Controller;

use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\TexterInterface;
use Symfony\Component\Routing\Annotation\Route;

class SecurityController
{
    /**
     * @Route("/login/success")
     */
    public function loginSuccess(TexterInterface $texter)
    {
        $sms = new SmsMessage(
            // the phone number to send the SMS message to
            '+1411111111',
            // the message
            'A new login was detected!'
        );

        $texter->send($sms);

        // ...
    }
}

See also

Read the main Notifier guide to see how to configure the different transports.

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.