| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
PHEM (PHP Email Management) is a versatile library designed to simplify email operations in your PHP projects. It provides a unified interface for interacting with SMTP, IMAP, and POP3 protocols, enabling you to send and receive emails with ease. PHEM supports secure connections, authentication, and provides logging for debugging and monitoring.
Simply include the PHEM.php file in your project:
require_once 'PHEM.php';Before using PHEM, you need to configure the connection settings for the desired protocol (SMTP, IMAP, or POP3).
SMTP Configuration:
PHEM::smtp('smtp.example.com', 587, 'tls'); // Host, Port, Security
PHEM::smtpLogin('your_smtp_username', 'your_smtp_password');IMAP Configuration:
PHEM::imap('imap.example.com', 993, '/ssl'); // Host, Port, Security
PHEM::imapLogin('your_imap_username', 'your_imap_password');POP3 Configuration:
PHEM::pop('pop.example.com', 995, '/ssl'); // Host, Port, Security
PHEM::popLogin('your_pop_username', 'your_pop_password');$from = 'sender@example.com';
$name = 'Sender Name';
$to = 'recipient@example.com';
$cc = 'cc@example.com'; // Optional
$bcc = 'bcc@example.com'; // Optional
$subject = 'Email Subject';
$message = 'Email body text';
if (PHEM::smtpSend($from, $name, $to, $cc, $bcc, $subject, $message)['status']) {
echo "Email sent successfully!";
PHEM::showLog(); // Optional: display the SMTP transaction log.
} else {
echo "Email sending failed.";
}$filter = 'unread'; // See filtering options below.
$limit = 10; // Number of emails to retrieve
$emails = PHEM::imapGet($filter, $limit);
if (!empty($emails)) {
foreach ($emails as $email) {
echo "Subject: " . $email['subject'] . "<br>";
echo "From: " . $email['from'] . "<br>";
echo "Date: " . $email['date'] . "<br>";
echo "Message: " . $email['message'] . "<br><hr>";
}
} else {
echo "No emails found.";
}Though the library code has a popGet function, it's declared as private. If you need POP3 functionality, you would need to modify the code to make popGet public. Its usage would then be similar to imapGet:
// Assuming popGet is made public
$filter = 'unread'; // See filtering options below.
$limit = 10; // Number of emails to retrieve
$emails = PHEM::popGet($filter, $limit);
// ... process emails (similar to IMAP example)The $filter parameter in the imapGet and popGet methods accepts the following filter criteria:
To view the SMTP transaction log, call the showLog() method after sending an email:
PHEM::showLog();This will output the SMTP communication details in a <pre> block, which can be helpful for debugging.
Contributions are welcome! If you find any bugs or have suggestions for improvement, please feel free to open an issue or submit a pull request.
This project is licensed under the MIT License.
| Back | FazBrowse Home | New Git URL |