Send your emails and sms easily with your favourite php framework, Symfony!
Discover the integration of Sweego with Symfony 7.2 for your emails and SMS messages
We’re delighted to announce that Sweego, your email and SMS SAAS solution, is now fully integrated with Symfony’s Mailer and Notifier components. With the release of Symfony 7.2, this integration offers a simple and efficient way to connect your mailers directly to your Symfony applications.
What is Symfony ?
In case some of you haven’t heard of Symfony yet, it’s one of the most popular and powerful PHP frameworks, used by thousands of developers and businesses around the world (over 600,000 developers) to create robust, scalable, high-performance web applications. With its modular architecture and vast community, Symfony makes development easier thanks to its many reusable components and high standards.
Why choose Sweego with Symfony?
- European sovereignty: Your data remains in Europe and complies with the RGPD.
- A robust, easy-to-use API: Compatible with Mailer for email and Notifier for SMS.
- Flexibility: Customise your integrations with full webhook support.
- Expert in deliverability: Sweego employees have decades of experience in sending mass emails, with several billion sent each year.
Quick implementation with Symfony 7.2
Prerequisites
Before you start, make sure you have :
- A Sweego API key. You can generate this from your Sweego customer area (see documentation).
- A domain validated on the Sweego platform for sending emails.
Package installation
Add the necessary packages to your Symfony :
composer require symfony/sweego-mailer symfony/sweego-notifier
Configure Mailer to send emails with Sweego
Add your Sweego configuration to your project’s .env file:
Send via SMTP :
# SMTP
MAILER_DSN=sweego+smtp://LOGIN:PASSWORD@HOST:PORT
Send via API :
# API
MAILER_DSN=sweego+api://API_KEY@default
In your application, sending an email becomes simple:
use Symfony\Component\Mailer\Transport\TransportInterface;
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mime\Email;
public function sendEmail(TransportInterface $transport): void
{
$mailer = new Mailer($transport);
$email = (new Email())
->from('example@yourdomain.com')
->to('recipient@example.com')
->subject('Hello from Sweego!')
->text('This is a test email sent using Symfony Mailer and Sweego.');
$mailer->send($email);
}
Configure Notifier to send text messages with Sweego
Add the following configuration for Sweego to the services.yaml file:
framework:
notifier:
texter_transports:
sweego: '%env(SWEEGO_SMS_DSN)%'
Add your Sweego API key to the .env file:
SWEEGO_SMS_DSN=sweego://API_KEY@default?region=REGION&campaign_type=CAMPAIGN_TYPE&bat=BAT&campaign_id=CAMPAIGN_ID&shorten_urls=SHORTEN_URLS&shorten_with_protocol=SHORTEN_WITH_PROTOCOL
Where :
API_KEY
(required) is your Sweego API keyREGION
(required) is the region of the phone number (e.g.FR
, ISO 3166-1 alpha-2 country code)CAMPAIGN_TYPE
(required) is the type of the campaign (e.g.transac
)BAT
(optional) sends a test sms to your test sms number (e.g.true
)CAMPAIGN_ID
(optional) is the campaign id (e.g.string
)SHORTEN_URLS
(optional) is the shorten urls option (e.g.true
)SHORTEN_WITH_PROTOCOL
(optional) is the shorten with protocol option (e.g.true
)
Send a text message directly from your application:
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\TexterInterface;
public function sendSms(TexterInterface $texter): void
{
$sms = new SmsMessage(
'+123456789', // Numéro du destinataire
'Hello! This SMS was sent using Symfony Notifier and Sweego.'
);
$texter->send($sms);
}
Real-time monitoring with webhooks
With the integration of webhooks, you can receive real-time notifications of events in your mailings. For example, an email delivered, an SMS failed, etc. Consult our documentation to configure your webhooks in Sweego.
Repositories GitHub
Find Sweego components for Symfony on GitHub :
- Sweego Mailer : Documentation and code for sending emails.
- Sweego Notifier : Documentation and code for sending SMS.
With this new integration, we’re simplifying the use of Sweego in your Symfony projects. If you have any questions or want to explore more features, feel free to ask us on Slack or Discord or request a new feature on our feedback tool.
The Sweego team is pleased to have sponsored the development of these components thanks to the excellent work of Welcomattic.