Skip to content

Instantly share code, notes, and snippets.

@a-r-m-i-n
Created May 17, 2016 07:58
Show Gist options
  • Select an option

  • Save a-r-m-i-n/023e7b0ad87cf3478a660f58b5c3a441 to your computer and use it in GitHub Desktop.

Select an option

Save a-r-m-i-n/023e7b0ad87cf3478a660f58b5c3a441 to your computer and use it in GitHub Desktop.
Basic Usage of SwiftMailer
<?php
require_once('vendor/autoload.php'); // get and include swift mailer library via composer
$text = 'Hallo!
Dies ist eine Test-E-Mail.
Vielen Dank und schöne Grüße';
// New message instance with basic mail settings
$message = \Swift_Message::newInstance();
$message
->setSubject('Mail subject')
->setFrom('me@domain.com')
->setTo('you@domain.com')
->setBody(nl2br($text), 'text/html', 'utf8');
// Add attachment to mail
$message->attach(\Swift_Attachment::fromPath($pathToPdf));
// Define a mailer (this is a sendmail example)
$mailTransport = \Swift_SendmailTransport::newInstance();
$mailer = \Swift_Mailer::newInstance($mailTransport);
// Use mailer to send message
$status = $mailer->send($message);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment