Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Testing external SMTP server with PHP
<?php
# use composer : php composer.phar require swiftmailer/swiftmailer @stable
require __DIR__ . '/vendor/autoload.php';
// Approach 1: Change the global setting (suggested)
Swift_Preferences::getInstance()->setCharset('utf-8');
$smtp_host = '1.2.3.4';
// 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@host.it' => 'No reply'));
$message->setTo(array('fromemail@mail.it' => '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:";
print_r($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.