effectra/mail

Effectra Mail 包。

v2.1.0 2023-12-29 09:01 UTC

This package is auto-updated.

Last update: 2024-10-01 00:17:07 UTC


README

Effectra\Mail 是一个提供灵活且易于使用的邮件发送功能的应用程序包。它支持多个邮件驱动程序,并允许您配置各种邮件设置,如邮件服务器主机、端口、身份验证等。

功能

  • 支持多个邮件驱动程序(SMTP、sendmail 等)
  • 邮件服务器设置配置选项
  • 易于设置和使用
  • 邮件发送错误的异常处理

安装

您可以通过 Composer 安装 Effectra-Mail 包。在您的终端中运行以下命令

composer require effectra/mail

用法

创建 Mailer 实例

要使用 Effectra-Mail 包发送电子邮件,您需要创建一个邮件发送实例。MailerFactory 类提供了一个方便的方式来创建邮件发送实例

use Effectra\Mail\Mailer;

// Create a mailer instance
$mailer = new Mailer(
    'smtp',         // Mail driver (e.g., 'smtp', 'sendmail')
    'mail.example.com',  // Mail server host
    587,            // Mail server port
    'username',     // Username for authentication
    'password',     // Password for authentication
    'info@example.com'  // "From" email address
);

发送电子邮件

一旦您有了邮件发送实例,您就可以使用它来发送电子邮件。Mailer 类提供了设置电子邮件收件人、主题、内容等方法。以下是一个发送电子邮件的示例

$mail = new Mail();
// Set email recipients
$mail->to('recipient1@example.com');
$mail->cc('recipient2@example.com');
$mail->bcc('recipient3@example.com');

// Set email subject and content
$mail->subject('Hello, world!');
$mail->text('This is the plain text content of the email.');
$mail->html('<p>This is the HTML content of the email.</p>');

// Send the email
try {
    $mailer->send($mail);
    echo 'Email sent successfully!';
} catch (Exception $e) {
    echo 'An error occurred while sending the email: ' . $e->getMessage();
}

请随意探索 Mailer 类及其方法,以根据您的需求自定义电子邮件发送过程。

许可证

此包是开源软件,根据 MIT 许可证 许可。

贡献

欢迎贡献!如果您遇到任何问题或对改进有建议,请创建一个问题或提交 GitHub 仓库的拉取请求。

致谢

Effectra-Mail 由 Mohammed Taha 开发和维护。

支持

有关 Effectra-Mail 包的任何问题或支持,请联系 support@example.com