machour / swiftmailer-ethereal-transport
A simple Ethereal transport for Swift Mailer
Installs: 2 995
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.0|^8.1
- swiftmailer/swiftmailer: ^5.1 || ^6.0
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.