Skip to content

leafsphp/mail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation



Leaf Mail Module



Leaf Mail v2

Latest Stable Version Total Downloads License

Mailing in PHP apps has always been seen as a daunting task. Leaf Mail provides a simple, straightforward and efficient email API that is built on the widely used PHPMailer Library component.

With Leaf Mail, you can easily send emails using various drivers and services such as SMTP, Mailgun, SendGrid, Amazon SES, and sendmail. This flexibility enables you to swiftly begin sending emails through a preferred local or cloud-based service.

Installation

You can install leaf mail using the leaf cli:

leaf install mail

or with composer:

composer require leafs/mail

Basic Usage

Leaf Mail provides a Mailer class that is responsible for validating and sending emails. This class handles the connection to your mail server, the configuration for how to send your emails and the actual sending of emails.

It also provides a mailer() method that is responsible for creating and formatting emails. Most of the time, you'll be using the mailer() method to create and send emails.

Note that you need to setup the connection to your mail server using the Leaf\Mail\Mailer class before sending your emails.

Configure your mailer

use Leaf\Mail\Mailer;
use PHPMailer\PHPMailer\PHPMailer;

...

Mailer::connect([
  'host' => 'smtp.mailtrap.io',
  'port' => 2525,
  'charSet' => PHPMailer::CHARSET_UTF8,
  'security' => PHPMailer::ENCRYPTION_STARTTLS,
  'auth' => [
    'username' => 'MAILTRAP_USERNAME',
    'password' => 'MAILTRAP_PASSWORD'
  ]
]);

Send your mails

mailer()
  ->create([
    'subject' => 'Leaf Mail Test',
    'body' => 'This is a test mail from Leaf Mail using gmail',

    // next couple of lines can be skipped if you
    // set defaults in the Mailer config
    'recipientEmail' => '[email protected]',
    'recipientName' => 'First Last',
    'senderName' => 'Leaf Mail',
    'senderEmail' => '[email protected]',
  ])
  ->send();