Skip to content

Instantly share code, notes, and snippets.

@jptoto
Created August 13, 2013 20:27
Show Gist options
  • Save jptoto/6225332 to your computer and use it in GitHub Desktop.
Save jptoto/6225332 to your computer and use it in GitHub Desktop.
Swift PHP Mailer Example
<?php
require_once 'lib/swift_required.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('staging-smtp.postmarkapp.com', 2525)
->setUsername('api_key')
->setPassword('api_key')
;
/*
You could alternatively use a different transport such as Sendmail or Mail:
// Sendmail
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
// Mail
$transport = Swift_MailTransport::newInstance();
*/
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Test from Swift 5')
->setFrom(array('email5@email.com' => 'JP Toto'))
->setTo(array('email4@email.com'))
->setBody('Here is the message itself')
->setCc(array('email3@email.com'))
->setBcc(array('email2@amil.com', 'email@email1.com'))
;
// Send the message
$result = $mailer->send($message);
print $result;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment