leafs / mail
Leaf PHP bareui templating engine
Fund package maintenance!
Open Collective
leafsphp
Installs: 1 144
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 2
Forks: 5
Open Issues: 1
Requires
- phpmailer/phpmailer: ^6.5
README
Leaf Mail Module
Leaf Mail v2
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' => 'name@mail.com', 'recipientName' => 'First Last', 'senderName' => 'Leaf Mail', 'senderEmail' => 'mychi@leafphp.dev', ]) ->send();