1. Go to this page and download the library: Download pe/component-smtp library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pe / component-smtp example snippets
namespace PE\Component\SMTP;
$host = 'example.com';// Your server host
$port = 587; // Your server port
$security = true; // Enable/disable server ssl security
$validate = false; // Enable/disable certificate verification
// Create client
$client = new Client(new Connection($host, $port, $security, $validate));
// Send message minimal flow
$client->connect();
$client->HELO();
$client->MAIL('[email protected]');
$client->RCPT('[email protected]');
$message = "
From: <[email protected]>\n
To: <[email protected]>\n
Subject: HELLO\n
Content-Type: text/plain\n
\n
HELLO
";
$client->DATA($message);
$client->QUIT();
namespace PE\Component\SMTP;
// For enable module you need to disable connection security and use one of options
$client = new Client(new Connection('example.com', 587, false));
// Option 1: upgrade connection if TLS supported (default)
$client->attachModule(new Module\ModuleStartTLS());
// Option 2: force TLS, if not supported - exception will be thrown
$client->attachModule(new Module\ModuleStartTLS(true));
namespace PE\Component\SMTP;
$client = new Client(new Connection());
// For enable module first you need to configure authenticators
$module = new Module\ModuleAuthenticator([
new Authenticator\AuthenticatorPlain(),
new Authenticator\AuthenticatorLogin(),
new Authenticator\AuthenticatorCramMD5(),
]);
// Then you must set your credentials
$module->setUsername('username');
$module->setPassword('password');
// And then you can attach module
$client->attachModule($module);
namespace PE\Component\SMTP;
$client = new Client(new Connection());
// Option 1: use STDOUT handler
$client->attachModule(
new Module\ModuleLogger(new LogHandler\LogHandlerSTDOUT())
);
// Option 2: use PSR handler
/* @var $psrLogger \Psr\Log\LoggerInterface */
$client->attachModule(
new Module\ModuleLogger(new LogHandler\LogHandlerPSR($psrLogger))
);
namespace PE\Component\SMTP;
use PE\Component\SMTP\Module\ModuleDSN;
$module = new ModuleDSN();
// For enable you can use any combination of constants below
$module->setNotify([
ModuleDSN::NOTIFY_SUCCESS,
ModuleDSN::NOTIFY_DELAY,
ModuleDSN::NOTIFY_FAILURE,
]);
// For disable you can pass only or just empty array
$module->setNotify([ModuleDSN::NOTIFY_NEVER]);
// For return only headers in delivery report
$module->setReturn(ModuleDSN::RETURN_HEADERS);
// For return full body in delivery report
$module->setReturn(ModuleDSN::RETURN_FULL);
$client = new Client(new Connection());
$client->attachModule($module);
namespace PE\Component\SMTP;
// For enable module just attach it
$client = new Client(new Connection());
$client->attachModule(new Module\ModulePipelining());
namespace PE\Component\SMTP;
// For enable module just attach it
$client = new Client(new Connection());
$client->attachModule(new Module\ModuleSMTPUTF8());
namespace PE\Component\SMTP;
// For enable module just attach it
$client = new Client(new Connection());
$client->attachModule(new Module\Module8BitMIME());
php composer.phar
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.