brbunny/brmailer
BrMailer 是一个用于处理电子邮件的 PHPMAILER 组件
Requires
- php: >=7.2
- ext-pdo: >=7.2
- brbunny/brplates: 1.*
- phpmailer/phpmailer: 6.*
README
BrMailer 是一个使用 PHPMAILER 处理电子邮件的组件。
安装
BrMailer 通过 Composer 提供
"brbunny/brmailer": "1.1.*"
或运行
composer require brbunny/brmailer
文档
有关如何使用 BrMailer 的更多详细信息,请参阅组件目录中的示例文件夹
配置
要开始使用 BrMailer,我们需要配置电子邮件数据。在项目的配置文件中放入常量 BRMAILER
并根据您的偏好更改值。要了解更多信息,请访问 Component PHPMailer
为了开始使用 BrMailer,我们需要配置电子邮件数据。在您的项目配置文件中放置常量 BRMAILER
并根据您的偏好更改值。要了解更多信息,请访问 Componente PHPMailer
<?php define("BRMAILER", [ "host" => "mail.host.com", "port" => "587", "user" => "user@example.com", "passwd" => "secret", "from" => [ "name" => "From Name", "address" => "from@example.com" ], "reply" => [ "name" => "Reply Name", "address" => "info@example.com" ], "options" => [ "language" => "br", // Set Language Email "smtp_debug" => 0, // Enable verbose debug output "is_html" => true, // Set email format to HTML "auth" => true, // Enable SMTP authentication "secure" => "tls or ssl", // Enable TLS encryption "charset" => "utf-8" // Set email charset ] ]);
引导
要向单个收件人发送电子邮件,请在 bootstrap()
函数中将目标电子邮件地址作为参数添加。但是,您也可以使用 addAddress()
函数或同时使用这两个函数。
要向单个收件人发送电子邮件,请在 bootstrap()
函数中将目标电子邮件地址作为参数添加。不过,您也可以使用 addAddress()
函数或同时使用这两个函数。
<?php require __DIR__ . '/vendor/autoload.php'; use BrBunny\BrMailer\BrMailer; $email = new BrMailer(); // (string Subject, string Body, string RecipientAddress, string RecipientName) $email->bootstrap( "Here is the subject", "This is the message body", "van@example.com", // E-mail is Optional "Van User" // Name is Optional );
模板
现在您可以使用 BrPlates 组装您的 HTML 电子邮件模板,使用 template()
方法创建模板。有关更多详细信息,请访问示例文件夹,了解其工作方式,或访问 BrPlates。
现在您可以使用 BrPlates 组装您的 HTML 电子邮件模板,只需使用 template()
方法创建模板。有关更多详细信息,请访问示例文件夹,了解其工作方式,或访问 BrPlates。
<?php $template = $email->template("./theme")->renderTemplate("_theme", [ "title" => "E-mail", "company" => "BrBunny" ]); $email->bootstrap( "Here is the subject", $template );
添加地址
如果不在 bootstrap 函数中作为参数输入电子邮件,则必须使用 addAddress()
函数。
如果不在 bootstrap 函数中作为参数输入电子邮件,则必须使用 addAddress()
函数。
<?php $email->addAddress("joe@example.net", "Joe User"); $email->addAddress("jhow@example.com"); // Name is optional
添加 CC
如果您使用 addAddress()
或 addCC()
函数添加多个收件人,他们将会知道谁收到了消息。
如果使用 addAddress()
或 addCC()
函数添加多个收件人,他们将会知道谁收到了消息。
<?php $email->addCC("joe@example.net", "Joe User"); $email->addCC("jhow@example.com"); // Name is optional
添加 BCC
addBCC()
函数将电子邮件发送给多个人,但其中一个人不知道其他人也在接收相同的消息。
addBCC()
函数将电子邮件发送给多个人,但其中一个人不知道其他人也在接收相同的消息。
<?php $email->addBCC("joe@example.net", "Joe User"); $email->addBCC("jhow@example.com"); // Name is optional
附件
<?php // Add Attachment in E-mail $email->attach("/tmp/image.jpg", "Image"); $email->attach("/tmp/file.pdf"); // Name is optional
发送电子邮件
<?php // string $from, string $fromName, string $replyTo, string $replyToName if($email->send()){ // Message success echo "Success Send"; }else{ // Get message error echo $email->fail()->getMessage(); }
鸣谢
- Kevin S. Siqueira(此库的开发者)
- PHPMailer(发送电子邮件的库)
许可
MIT 许可证(MIT)。有关更多信息,请参阅 许可文件。