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.
- 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)
Install via Composer:
composer require lazervel/mailsenderOr manually add to your composer.json:
{
"require": {
"lazervel/mailsender": "^1.0"
}
}<?php
require 'vendor/autoload.php';
use Lazervel\MailSender\MailSender;
$mail = new MailSender(
name: 'My App',
email: '[email protected]',
password: 'yourpassword'
);
// Single recipient
$mail->addMail('John Doe', '[email protected]');
$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!";
}$recipients = [
[
'name' => 'User One',
'email' => '[email protected]',
'subject' => 'Hello!',
'body' => '<p>This is a test email.</p>'
],
[
'name' => 'User Two',
'email' => '[email protected]',
'subject' => 'Another Mail',
'body' => '<p>This is another email.</p>'
]
];
$mail->sendTo($recipients)->send();$mail->addAttachment('/path/to/file.pdf');$mail->addTmpFileAttachment($_FILES['file']);$mail->addStringAttachment($dataUrl, 'document.pdf');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.
You can define these in your .env file or system environment:
MAILER_NAME="My App"
MAILER_EMAIL="[email protected]"
MAILER_PASSWORD="yourpassword"
APP_NAME="My App"
MailSender/
├── composer.json
├── README.md
├── src/
│ ├── MailSender.php
│ └── Exception/
│ └── ConfigurationException.php
└── tests/
└── MailSenderTest.php
vendor/bin/phpunitThis project is open-sourced under the MIT License.
Feel free to use, modify, and distribute with attribution.