PHP Socket Mailer
PHP SMTP Mailer library implemented by socket, (*1)
, (*2)
DEMONSTRATION
$mailer = new \yidas\socketMailer\Mailer([
'host' => 'mail.your.com',
'username' => 'service@your.com',
'password' => 'passwd',
]);
$result = $mailer
->setSubject('Mail Title')
->setBody('Content Text')
->setTo(['name@your.com', 'peter@your.com' => 'Peter'])
->setFrom(['service@your.com' => 'Service Mailer'])
->setCc(['cc@your.com' => 'CC Receiver'])
->setBcc(['bcc@your.com'])
->send();
REQUIREMENTS
This library requires the following:, (*3)
INSTALLATION
Run Composer in your project:, (*4)
composer require yidas/socket-mailer
Then you could call it after Composer is loaded depended on your PHP framework:, (*5)
require __DIR__ . '/vendor/autoload.php';
use \yidas\socketMailer\Mailer;
CONFIGURATION
To use localhost MTA:, (*6)
$mailer = new \yidas\socketMailer\Mailer()
To configure a external MTA server:, (*7)
$mailer = new \yidas\socketMailer\Mailer([
'host' => 'mail.your.com',
'username' => 'service@your.com',
'password' => 'passwd',
'port' => 587,
'encryption' => 'tls',
]);
SSL Connection
$mailer = new \yidas\socketMailer\Mailer([
// ...
'port' => 465,
'encryption' => 'ssl',
]);
Non-Auth Connection
If you want to connect to SMTP relay server with free auth in allowed networks:, (*8)
$mailer = new \yidas\socketMailer\Mailer([
'host' => 'mail.your.com',
'port' => 25,
]);
USAGES
debugOn()
public self debugOn()
setFrom()
public self setFrom(string|array $form)
setTo()
public self setTo(array $recipients)
setCc()
public self setCc(array $recipients)
setBcc()
public self setBcc(array $recipients)
setBody()
public self setBody(string $text)
setSubject()
public self setSubject(string $title)
public self addHeader($key, $value)
Example:, (*9)
$mailer = $mailer->addHeader('Your-Header-Name', 'the header value');
send()
public boolean send()