leafs / mail
Leaf PHP bareui 模板引擎
v2.1
2024-03-05 18:09 UTC
Requires
- phpmailer/phpmailer: ^6.5
README
Leaf 邮件模块
Leaf Mail v2
在PHP应用中,邮件发送一直被视为一项艰巨的任务。Leaf Mail提供了一种简单、直接且高效的邮件API,它基于广泛使用的PHPMailer库组件构建。
使用Leaf Mail,您可以使用SMTP、Mailgun、SendGrid、Amazon SES和sendmail等多种驱动程序和服务轻松发送邮件。这种灵活性使您能够快速通过首选的本地或基于云的服务开始发送邮件。
安装
您可以使用leaf cli安装leaf mail
leaf install mail
或者使用composer
composer require leafs/mail
基本用法
Leaf Mail提供了一个Mailer类,负责验证和发送邮件。此类处理与您的邮件服务器的连接、发送邮件的配置以及实际发送邮件。
它还提供了一个mailer()方法,用于创建和格式化邮件。大多数情况下,您将使用mailer()方法来创建和发送邮件。
请注意,在发送邮件之前,您需要使用Leaf\Mail\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' ] ]);
发送您的邮件
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();