Skip to content

Instantly share code, notes, and snippets.

@bencooling
Last active December 19, 2015 09:29
Show Gist options
  • Save bencooling/5933592 to your computer and use it in GitHub Desktop.
Save bencooling/5933592 to your computer and use it in GitHub Desktop.
PHP: boilerplate code for php libraries Swiftmailer, Illuminate

##php: boilerplate code for various php libraries Sample php code for php libraries found in packagist

  • Swiftmailer
$translator = new Symfony\Component\Translation\Translator('en');
$validator = new Illuminate\Validation\Factory($translator);
<?php
require 'vendor/autoload.php';
// SMTP
$transport = Swift_SmtpTransport::newInstance()
->setHost('smtp.gmail.com')
->setPort(465)
->setEncryption('ssl')
->setUsername('xxxx@gmail.com')
->setPassword('');
// Create the message
$message = Swift_Message::newInstance()
->setSubject('Test subject')
->setFrom(array('xxxx@gmail.com' => 'Ben Cooling'))
->setTo(array('yyyy@bcooling.com.au' => 'Ben Cooling'))
->setBody('Here is the message itself')
->addPart('<q>Here is the message itself</q>', 'text/html');
// Send the message
$mailer = Swift_Mailer::newInstance($transport);
$result = $mailer->send($message);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment