This is a very simple PHP SMTP email client.
$mailer = new Mailer( string $host, int $port, string $username, string $password[, int $method = Mailer::SMTP] );
Method
Mailer::SMTP
- Normal SMTP authentication.
Mailer::XOAUTH2
- Uses oAuth SMTP server.
$mailer = new Mailer('ssl://smtp.example.com', 465, 'me@example.com', 'my@password', Mailer::SMTP);
Requests a read receipt when recipient email client supports this feature.
$mailer->enableReadReceipt( );
$mail->enableReadReceipt();
Enables delivery status report. Only supported by some SMTP servers.
$mailer->enableDeliveryStatus( );
$mailer->enableDeliveryStatus();
Some SMTP servers required custom hello string.
$mailer->setHello( string $hello );
$mailer->setHello('EHLO');
Adds recipient for the email.
bool $mailer->addAddress( string $email[, string $name][, int $type = Mailer::TO] );
Type | Description |
---|---|
Mailer::TO | Normal recipient. |
Mailer::CC | Carbon copy of the email to this recipient. |
Mailer::BCC | Blind carbon copy of the email. Others recipient will no seeing this recipient in the list. |
// Add a recipient
$mailer->addAddress('peter@example.com', 'Peter');
// CC the email to alice@exmaple.com
$mailer->addAddress('alice@example.com', 'Alice', Mailer::CC);
// BCC the email to boss
$mailer->addAddress('boss@example.com', 'Boss', Mailer::BCC);
Sets a reply-to address if you want recipient to reply your email to another address.
bool $mailer->setReplyTo(string $email[, string $name]);
$mailer->setReplyTo('another@example.com', 'Another Me');
Adds attachment.
bool $mailer->addAttachment( string $file[, string $name] );
$mailer->addAttachment('/home/me/revenue_report.docx');
Adds custom headers.
$mailer->addHeader( string $key, string $value );
$mailer->addHeader('X-Mailer', 'My-Custom-Email-Client');
Sends the email.
bool $mailer->send( string $from_email, string $from_name, string $subject, string $body[, int $mode = Mailer::TEXT][, string $plain_text_body] );
Mode
Mailer::TEXT
- Sends a plain text email.
Mailer::HTML
- Sends a HTML email.
// Send plain text email
$result = $mailer->send('me@example.com', 'Me', 'Test Message', 'This is just a test message.');
// Send HTML email
$result = $mailer->send('me@example.com', 'Me', 'Test Message', 'This is just a <strong>test message</strong>.', Mailer::HTML, 'This is just a test message.');
Gets SMTP logs.
array $mailer->getLogs();
// Print out full SMTP logs
echo '<pre>';
echo htmlspecialchars(implode("\n", $mailer->getLogs()));
echo '</pre>';