tpsoft / emailer
Simple send plain text and HTML e-mails over SMTP server with save messages in IMAP server.
v1.0.1
2025-06-21 18:58 UTC
Requires
- pear/mail: ^2.0
- pear/mail_mime: ^1.10
- pear/net_smtp: ^1.12
README
Simple send plain text and HTML e-mails over SMTP server with save messages in IMAP server.
Installation
Via Composer
Install the package using Composer:
composer require tpsoft/emailer
Via Git Repository
Clone the repository directly from the Git server:
git clone https://gitea.tpsoft.org/TPsoft.org/Emailer.git
cd Emailer
composer install
Requirements
- PHP 7.0 or higher
- PEAR Mail package (automatically installed via Composer)
- PEAR Net_SMTP package (automatically installed via Composer)
- PEAR Mail_Mime package (automatically installed via Composer)
Usage
Basic Example
<?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>'
);
Configuration Options
SMTP Configuration
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')
IMAP Configuration (Optional)
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 password
Method Parameters
The 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)
Features
- Send emails via SMTP with authentication
- Support for both plain text and HTML content
- Automatic saving of sent messages to IMAP folder
- SSL/TLS encryption support
- Easy configuration through array
License
This project is licensed under the GPL-3.0-or-later License.
Author
- Igor Mino - mino@tpsoft.org
Support
For issues and questions, please visit the repository at: https://gitea.tpsoft.org/TPsoft.org/Emailer