Mime Component
Syntax
use Symfony\Component\Mime\Email;
$email = (new Email())
->from(‘[email protected]’)
->to(‘[email protected]’)
->subject(‘Important Notification’)
->text(‘Lorem ipsum…’)
->html(‘
Lorem ipsum
…
’);
use Symfony\Component\Mime\Header\Headers;
use Symfony\Component\Mime\Message;
use Symfony\Component\Mime\Part\Multipart\AlternativePart;
use Symfony\Component\Mime\Part\TextPart;
$headers = (new Headers())
->addMailboxListHeader(‘From’, [‘[email protected]’])
->addMailboxListHeader(‘To’, [‘[email protected]’])
->addTextHeader(‘Subject’, ‘Important Notification’)
;
htmlContent = new TextPart(‘
Lorem ipsum
…
’, ‘html’);textContent, $htmlContent);
headers, $body);
Twig integeration
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
$email = (new TemplatedEmail())
->from(‘[email protected]’)
->to(‘[email protected]’)
// …
// this method defines the path of the Twig template to render
->htmlTemplate('messages/user/signup.html.twig')
// this method defines the parameters (name => value) passed to templates
->context([
'expiration_date' => new \DateTime('+7 days'),
'username' => 'foo',
])
;
Changelog
- [Notification Emails](Notification Emails)