PHP SMTP Mailer library implemented by socket
$mailer = new \yidas\socketMailer\Mailer([
'host' => 'mail.your.com',
'username' => '[email protected]',
'password' => 'passwd',
]);
$result = $mailer
->setSubject('Mail Title')
->setBody('Content Text')
->setTo(['[email protected]', '[email protected]' => 'Peter'])
->setFrom(['[email protected]' => 'Service Mailer'])
->setCc(['[email protected]' => 'CC Receiver'])
->setBcc(['[email protected]'])
->send();
This library requires the following:
- PHP 5.4.0+
Run Composer in your project:
composer require yidas/socket-mailer
Then you could call it after Composer is loaded depended on your PHP framework:
require __DIR__ . '/vendor/autoload.php';
use \yidas\socketMailer\Mailer;
To use localhost MTA:
$mailer = new \yidas\socketMailer\Mailer()
To configure a external MTA server:
$mailer = new \yidas\socketMailer\Mailer([
'host' => 'mail.your.com',
'username' => '[email protected]',
'password' => 'passwd',
'port' => 587,
'encryption' => 'tls',
]);
$mailer = new \yidas\socketMailer\Mailer([
// ...
'port' => 465,
'encryption' => 'ssl',
]);
If you want to connect to SMTP relay server with free auth in allowed networks:
$mailer = new \yidas\socketMailer\Mailer([
'host' => 'mail.your.com',
'port' => 25,
]);
public self debugOn()
public self setFrom(string|array $form)
public self setTo(array $recipients)
public self setCc(array $recipients)
public self setBcc(array $recipients)
public self setBody(string $text)
public self setSubject(string $title)
public self addHeader($key, $value)
Example:
$mailer = $mailer->addHeader('Your-Header-Name', 'the header value');
public boolean send()