Skip to content

Instantly share code, notes, and snippets.

@juriansluiman
Last active March 17, 2016 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juriansluiman/4d1acd1a9611a725622e to your computer and use it in GitHub Desktop.
Save juriansluiman/4d1acd1a9611a725622e to your computer and use it in GitHub Desktop.
Expl SlmMail

Transport vs service

Service is API client implementation. Does not correspond with any Zend\Mail transport interface. The HTTP transport class is an impl. of the Transport interface, accepting any of the SlmMail API client services. Actually, the SlmMail transport is a bridge between Zend Mail and all supported API service.

  1. Use the transport if you have previously have used Zend\Mail. It enables you to simply swap the Sendmail / SMTP transport and switch instantly to a 3rd party mail service
  2. Use the services if you only need the service implementation and have no need to further utilize Zend\Mail features

Using without Zend\Mail transport

use SlmMail\Service\MailgunService;
use Zend\Mail\Message;

$config  = ['domain' => 'my_domain', 'key' => 'asd123'];
$service = new MailgunService($config['domain'], $config['key']);

$message = new Message;
$message->setSubject('Hi there');

$result = $service->send($message);
var_dump($result);

Using with Zend\Mail transport

use SlmMail\Service\MailgunService;
use SlmMail\Mail\Transport\HttpTransport;
use Zend\Mail\Message;

$config    = ['domain' => 'my_domain', 'key' => 'asd123'];
$service   = new MailgunService($config['domain'], $config['key']);
$transport = new HttpTransport($service);

$message = new Message;
$message->setSubject('Hi there');

// Here you had previously a SMTP transport or Sendmail transport
// Now it is swapped with the Mailgun transport but the consumer code
// (this $transport->send()) is unaltered

$transport->send($message);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment