markguinn / silverstripe-email-helpers
该软件包最新版本(1.3.2)没有提供许可证信息。
包含SMTP邮件类和一些HTML邮件类别的Silverstripe扩展
1.3.2
2017-03-21 23:27 UTC
Requires
- pelago/emogrifier: ~1.0
- phpmailer/phpmailer: ^5.2.20
- silverstripe/framework: ~3.0
Requires (Dev)
- phpunit/phpunit: 3.7.*@stable
Replaces
This package is not auto-updated.
Last update: 2024-09-14 13:33:34 UTC
README
包含一个替换的Mailer对象,该对象利用PHPMailer通过SMTP发送电子邮件,而不是使用php的mail()函数。可选地,可以启用TLS与SMTP服务器进行安全通信,并可以指定电子邮件编码的字符集。此外,可以将内嵌的CSS和指定的外部CSS文件内联到电子邮件的HTML中。
还包括一个名为StyledHtmlEmail的Email类的替换版本。如果与HTML电子邮件一起使用,它允许您在电子邮件的顶部包含一个样式部分,然后将其作为实际的HTML标签上的style属性内联,以促进电子邮件客户端之间的更好的兼容性。
要求
Silverstripe 3.0+
安装
通过composer安装
composer require markguinn/silverstripe-email-helpers:dev-master
此模块安装PHPMailer和Emogrifier
用法
SMTP邮件器
要使用SMTP邮件器,请将以下代码添加到您的_config.php文件中
$encryption = 'tls'; // use tls $charset = 'UTF-8'; // use specified charset if set // you can specify a port as in 'yourserver.com:587' $mailer = new SmtpMailer('yourserver.com', 'username', 'password', $encryption, $charset); Email::set_mailer($mailer); // or Injector::inst()->registerService($mailer, 'Mailer');
或者,这些可以通过配置系统设置,如下所示
SmtpMailer:
host: yourserver.com
user: username
password: password
encryption: tls
charset: UTF-8
然后在_config.php中
Email::set_mailer( new SmtpMailer() );
Emogrified Smtp Mailer
如果您希望将CSS嵌入到电子邮件的HTML中,请使用EmogrifiedSmtpMailer
类。将以下代码添加到_config.php中
$encryption = 'ssl'; // use ssl $charset = 'UTF-8'; $externalcssfile = 'themes/{yourtheme}/css/externalcssfile.css'; // specify the path to your css file $SMTPDebug = 2; // Levels 0-4 available $logfailedemail = true; // Log a notice with PHPMailer's error information $mailer = new EmogrifiedSmtpMailer('yourserver.com', 'username', 'password', $encryption, $charset, $externalcssfile, $SMTPDebug, $logfailedemail); Email::set_mailer($mailer); // or Injector::inst()->registerService($mailer, 'Mailer');
或者,这些可以通过配置系统设置,如下所示
EmogrifiedSmtpMailer:
host: yourserver.com
user: username
password: password
encryption: ssl
charset: UTF-8
cssfile: 'themes/{yourtheme}/css/externalcssfile.css'
SMTPDebug: 2
logfailedemail: true
然后在_config.php中
Email::set_mailer( new EmogrifiedSmtpMailer() );
Styled Html Email
要使用样式化电子邮件,只需在通常使用Email类的地方使用StyledHtmlEmail类,并在电子邮件正文中添加一个单独的样式标签。例如
<style type="text/css"> .bigred { color: red; font-size: 30px; } </style> Hello <span class="bigred">CUSTOMERS</span>.
将会发送为
Hello <span style="color:red; font-size:30px">CUSTOMERS</span>.