Skip to content

Instantly share code, notes, and snippets.

@tsh-code
Created October 28, 2019 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsh-code/36d2bf283c932ff0164377f98537898d to your computer and use it in GitHub Desktop.
Save tsh-code/36d2bf283c932ff0164377f98537898d to your computer and use it in GitHub Desktop.
Symfony Mailer complex example
<?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