Created
May 17, 2016 07:58
-
-
Save a-r-m-i-n/023e7b0ad87cf3478a660f58b5c3a441 to your computer and use it in GitHub Desktop.
Basic Usage of SwiftMailer
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 | |
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('[email protected]') | |
->setTo('[email protected]') | |
->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