lazervel / mailsender
Modern PHP mailer built on PHPMailer for easy integration.
Fund package maintenance!
indianmodassir
Installs: 11
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/lazervel/mailsender
Requires
- php: >=5.5.0
- phpmailer/phpmailer: ^7.0
README
Lightweight PHP library for effortless email sending.
Built on top of PHPMailer, it provides an easy and elegant way to send HTML emails with inline CSS, embedded images, and attachments.
๐ Features
- Simple and clean wrapper for PHPMailer
- Inline CSS support (
<link rel="stylesheet">auto inlines to<style>) - Embedded local images automatically converted to CID
- File and base64 attachments support
- Handles multiple recipients with one call
- Easy integration with environment variables (
.envor$_ENV)
๐ฅ Installation
Install via Composer:
composer require lazervel/mailsender
Or manually add to your composer.json:
{
"require": {
"lazervel/mailsender": "^1.0"
}
}
๐งฉ Basic Usage
<?php require 'vendor/autoload.php'; use Lazervel\MailSender\MailSender; $mail = new MailSender( name: 'My App', email: 'youremail@gmail.com', password: 'yourpassword' ); // Single recipient $mail->addMail('John Doe', 'john@example.com'); $mail->mail->Subject = 'Welcome!'; $mail->mail->Body = '<h1>Hello John!</h1><p>Welcome to our app.</p>'; // Send if ($mail->send()) { echo "Mail sent successfully!"; } else { echo "Failed to send mail!"; }
๐ง Multiple Recipients Example
$recipients = [ [ 'name' => 'User One', 'email' => 'user1@example.com', 'subject' => 'Hello!', 'body' => '<p>This is a test email.</p>' ], [ 'name' => 'User Two', 'email' => 'user2@example.com', 'subject' => 'Another Mail', 'body' => '<p>This is another email.</p>' ] ]; $mail->sendTo($recipients)->send();
๐๏ธ Attachments
From File Path:
$mail->addAttachment('/path/to/file.pdf');
From Uploaded File ($_FILES):
$mail->addTmpFileAttachment($_FILES['file']);
From Base64 or URL:
$mail->addStringAttachment($dataUrl, 'document.pdf');
๐จ Inline CSS & Images
If your HTML contains linked CSS or image paths:
<link rel="stylesheet" href="style.css"> <img src="logo.png">
They will automatically be converted into inline <style> blocks and embedded CID images in the final email.
โ๏ธ Environment Variables (Optional)
You can define these in your .env file or system environment:
MAILER_NAME="My App"
MAILER_EMAIL="youremail@gmail.com"
MAILER_PASSWORD="yourpassword"
APP_NAME="My App"
๐งฑ Directory Structure
MailSender/
โโโ composer.json
โโโ README.md
โโโ src/
โ โโโ MailSender.php
โ โโโ Exception/
โ โโโ ConfigurationException.php
โโโ tests/
โโโ MailSenderTest.php
๐งช Testing
vendor/bin/phpunit
๐ License
This project is open-sourced under the MIT License.
Feel free to use, modify, and distribute with attribution.