mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-22 19:46:23 +00:00
1.4 KiB
1.4 KiB
id | title |
---|---|
c6a317d3-cdda-4c9b-bf03-5e36bce8bc57 | Mailer Component |
Description
Added in Symfony 4.3. Out of the box the following services are supported:
- Amazon SES
- MailChimp
- Mailgun
- Gmail
- Postmark
- SendGrid
Services need to be installed seperately:
composer require symfony/amazon-mailer
And environment variables need to be configured:
AWS_ACCESS_KEY=...
AWS_SECRET_KEY=...
MAILER_DSN=smtp://$AWS_ACCESS_KEY:$AWS_SECRET_KEY@ses
Syntax
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
class SomeService
{
private $mailer;
public function __construct(MailerInterface $mailer)
{
$this->mailer = $mailer;
}
public function sendNotification()
{
$email = (new Email())
->from('hello@example.com')
->to('you@example.com')
->subject('Time for Symfony Mailer!')
->text('Sending emails is fun again!')
->html('<p>See Twig integration for better HTML integration!</p>');
$this->mailer->send($email);
}
}
Signing Messages
It's also possible to sign and encrypt messages.