gelembjuk/mail
Composer 安装命令:
composer require gelembjuk/mail
包简介
Creates email body and subject from templates using Smarty or Twig and send email with one of supported mailes (PHPMailer, mail() function etc)
README 文档
README
PHP Package to send email with different mailers without changes in the PHP code and to format email messages using templater (Smarty, Twig).
Installation
Using composer: gelembjuk/mail require: {"gelembjuk/mail": "*"}
Configuration
$formatteroptions = array( 'locale' => '', // optional, add if you need international support 'deflocale' => 'en', // default locale. Optional as well, template from it are used if no in a `locale` 'templateprocessorclass' => null, // if not provided then smarty is used. this is one of classes from Gelembjuk/Templating 'templatecompiledir' => $thisdir.'/email_tmp/', // directory used to store tempopary files of cache engine . It i reuired for Smarty but not needed for Twig 'templatespath' => $thisdir.'/email_templates/' // a base path where email templates and files with subjects are stored ); $maileroptions = array( 'logger' => $logger, // (optional) Logger, instance of Gelembjuk\Logger\FileLogger, 'format' => $formatteroptions, // formatter options // other options related to specified email sending class // next options are only for PHPMailer 'mailsystem' => 'smtp', // for phpmailer it can be smtp or mail 'smtp_host' => 'smtp_host', // aka smtp.gmail.com 'smtp_port' => 25, // aka 587 'smtp_secure' => false, // or true in case of ssl/tls 'smtp_auth' => true, // usually true 'smtp_user' => 'smtp user', // aka your gmail account 'smtp_password' => 'smtp password', // your smtp password (gmail etc) );
Usage
$mailer = new \Gelembjuk\Mail\PHPMailer(); // OR // $mailer = new \Gelembjuk\Mail\PHPNative(); // uses mail() // OR // $mailer = new \Gelembjuk\Mail\NullMail(); // is only for testing, doesn't send only log $mailer->initMailer($maileroptions); $email_data = array( 'user' => 'John Smith', 'activationlink' => 'http://our_site.com/activateaccount/code' ); $mailer->formatAndSendEmail( 'activate', // template name $email_data, 'john_smith@gmail.com', // send to email 'from_email@gmail.com' // send from email );
Templates
In this example a templatespath must contain 3 files:
activate.htm - template for this email,
<h3>Hello {$user}</h3> <p>Click the link <a href="{$activationlink}">{$activationlink}</a></p>
out_default.htm - common out template used fro all emails (aka common header/footer for all emails)
<table> <tr><td>Header. Company name, logo etc</td></tr> <tr><td>{$EMAILCONTENT}</td></tr> <tr><td>Footer. Contacts, signature etc</td></tr> </table>
subjects.xml - contains text of email subjects for templates
<?xml version="1.0" encoding="utf-8"?> <templates> <activate> <subject>Activate your new account</subject> <description>This email is sent to a user when new account is registered</description> </activate> </templates>
Different template engines
Now Smarty and Twig can be used. See https://github.com/Gelembjuk/templating for more information. More supported engines can be added later.
Internationalization
See the test2.php in examples folder in this project. It shows how to organize structure of locales folders.
// send email with german template $mailer->setFormatterOption('locale','de'); $mailer->formatAndSendEmail( 'activate', // template name $email_data, 'john_smith@gmail.com', // send to email 'from_email@gmail.com' // send from email ); // send same email with french template $mailer->setFormatterOption('locale','fr'); $mailer->formatAndSendEmail( 'activate', // template name $email_data, 'john_smith@gmail.com', // send to email 'from_email@gmail.com' // send from email );
Author
Roman Gelembjuk (@gelembjuk)
gelembjuk/mail 适用场景与选型建议
gelembjuk/mail 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 92 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 07 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 gelembjuk/mail 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gelembjuk/mail 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 92
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-07-28