Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Testing external SMTP server with PHP
# use composer : php composer.phar require swiftmailer/swiftmailer @stable
require __DIR__ . '/vendor/autoload.php';
// Approach 1: Change the global setting (suggested)
$smtp_host = '';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance($smtp_host, 25);
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
$logger = new Swift_Plugins_Loggers_EchoLogger();
$mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
// Pass it as a parameter when you create the message
$message = Swift_Message::newInstance('Subject here', 'My amazing body');
$message->setFrom(array('' => 'No reply'));
$message->setTo(array('' => 'Christian'));
// Or set it after like this
$message->setBody('My <em>amazing</em> body', 'text/html');
// Send the message
if (!$mailer->send($message, $failures))
echo "Failures:";
} else {
echo "Sent";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.