![]() |
VOOZH | about |
Simple send plain text and HTML e-mails over SMTP server with save messages in IMAP server.
Install the package using Composer:
composer require tpsoft/emailer
Clone the repository directly from the Git server:
git clone https://gitea.tpsoft.org/TPsoft.org/Emailer.git
cd Emailer
composer install
<?php
require_once __DIR__ . '/vendor/autoload.php';
// Or if installed via Git: require_once __DIR__ . '/src/Emailer.php';
use TPsoft\Emailer\Emailer;
// Configuration array
$config = array(
'smtp' => array(
'host' => 'smtp.gmail.com',
'port' => 465,
'username' => 'your-email@gmail.com',
'password' => 'your-password',
'encryption' => 'ssl'
),
'imap' => array(
'host' => 'imap.gmail.com',
'port' => 993,
'encryption' => 'ssl',
'folder' => 'Sent',
'username' => 'your-email@gmail.com',
'password' => 'your-password'
)
);
// Create Emailer instance
$emailer = new Emailer($config);
// Send email with both plain text and HTML content
$emailer->send(
'recipient@example.com',
'Test Email at ' . date('Y-m-d H:i:s'),
'This is the plain text version of the message',
'<html><body style="color: red;">This is the <strong>HTML</strong> version of the message</body></html>'
);
host - SMTP server hostnameport - SMTP server port (usually 587 for TLS, 465 for SSL)username - SMTP authentication usernamepassword - SMTP authentication passwordencryption - Encryption type ('tls' or 'ssl')The IMAP configuration is used to save sent messages to your mail server's sent folder:
host - IMAP server hostnameport - IMAP server port (usually 993 for SSL, 143 for non-encrypted)encryption - Encryption type ('ssl' or leave empty for non-encrypted)folder - Folder name where sent messages will be saved (e.g., 'Sent', 'INBOX.Sent')username - IMAP authentication usernamepassword - IMAP authentication passwordThe send() method accepts the following parameters:
$emailer->send($to, $subject, $plainText, $htmlContent);
$to - Recipient email address$subject - Email subject line$plainText - Plain text version of the message$htmlContent - HTML version of the message (optional)This project is licensed under the GPL-3.0-or-later License.
For issues and questions, please visit the repository at: https://gitea.tpsoft.org/TPsoft.org/Emailer