Skip to content

Instantly share code, notes, and snippets.

@jptoto
Created August 13, 2013 20:27
Show Gist options
  • Select an option

  • Save jptoto/6225332 to your computer and use it in GitHub Desktop.

Select an option

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('[email protected]' => 'JP Toto'))
->setTo(array('[email protected]'))
->setBody('Here is the message itself')
->setCc(array('[email protected]'))
->setBcc(array('[email protected]', '[email protected]'))
;
// 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