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:
// 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);
// ...
}
}
参考
Read the main Notifier guide to see how to configure the different transports.