Created
October 28, 2019 10:55
-
-
Save tsh-code/36d2bf283c932ff0164377f98537898d to your computer and use it in GitHub Desktop.
Symfony Mailer complex example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
require_once __DIR__ . '/../vendor/autoload.php'; | |
use Symfony\Component\Mailer\Mailer; | |
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport; | |
use Symfony\Component\Mime\Email; | |
use Symfony\Component\Mime\NamedAddress; | |
$transport = new EsmtpTransport('192.168.99.100', 5025); | |
$mailer = new Mailer($transport); | |
$email = (new Email()) | |
->from(new NamedAddress('thomas@example.com', 'Thomas')) | |
->to(new NamedAddress('john@example.com', 'John')) | |
->subject('Symfony Mailer multipart e-mail') | |
->text('This is the text of the email.') | |
->html(fopen(__DIR__ . '/../template/mail.html', 'r')) | |
->attach(fopen(__DIR__ . '/../screen.png', 'r'), 'image-file-name.png', 'image/png') | |
; | |
$mailer->send($email); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment