machour/swiftmailer-ethereal-transport

A simple Ethereal transport for Swift Mailer

1.0.0 2022-09-17 15:40 UTC

This package is auto-updated.

Last update: 2024-10-17 20:45:22 UTC


README

This is a simple transport for Swift Mailer that uses Ethreal, the fake SMTP service.

This transport is meant to be used while developing your application, in order to preview the message, without it getting actually sent.

Using this transport, you can set a callback that will be invoked with the URL to the message preview as its first and only argument.

Installation

composer require machour/swiftmailer-ethereal-transport

Usage

use Machour\SwiftMailerEtherealTransport\EtherealTransport;

// Create the Transport
$transport = (new EtherealTransport())
  // Get your credential at https://ethereal.email/create
  ->setUsername('your username')
  ->setPassword('your password')
  // Display the URL in your logs, store it session, or whatever ..
  ->setCallback(function (string $url) use ($logger) {
      $logger->debug("Email sent to Ethereal, see it at $url");
  });

// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);

// Create a message
$message = (new Swift_Message('Wonderful Subject'))
  ->setFrom(['john@doe.com' => 'John Doe'])
  ->setTo(['receiver@domain.org', 'other@domain.org' => 'A name'])
  ->setBody('Here is the message itself');

// Send the message
$result = $mailer->send($message);

Note

Note Swift Mailer is deprecated, use this extension if you're stuck with a legacy app.

See also