提交 af30ab60 编写于 作者: R root

邮件结构进行了大调整

上级 9383fd28
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\app\appfront\helper\mailer;
use Yii;
use fec\helpers\CConfig;
use fec\controllers\FecController;
use yii\base\InvalidValueException;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Email
{
/**
* 说明:
* 本函数是静态函数方法,您可以直接调用,如果想要在本地重写这个文件
* 可以通过Yii 的classMap的方式进行重写,也就是,
* 在@app/config/YiiClassMap.php文件中添加配置即可
* 原理请参看文章:http://www.fancyecommerce.com/2016/10/13/%e9%80%9a%e8%bf%87%e9%85%8d%e7%bd%ae%e7%9a%84%e6%96%b9%e5%bc%8f%e9%87%8d%e5%86%99%e6%9f%90%e4%b8%aayii2-%e6%96%87%e4%bb%b6-%e6%88%96%e7%ac%ac%e4%b8%89%e6%96%b9%e6%89%a9%e5%b1%95%e6%96%87%e4%bb%b6/
*/
/**
* 得到联系我们的邮箱地址
*/
public static function contactsEmailAddress(){
$mailerConfig = Yii::$app->params['mailer'];
if(isset($mailerConfig['contacts']['emailAddress'])){
return $mailerConfig['contacts']['emailAddress'];
}
}
/**
* 得到Store Name
*/
public static function storeName(){
$mailerConfig = Yii::$app->params['mailer'];
if(isset($mailerConfig['storeName'])){
return $mailerConfig['storeName'];
}
}
public static function contactsPhone(){
$mailerConfig = Yii::$app->params['mailer'];
if(isset($mailerConfig['phone'])){
return $mailerConfig['phone'];
}
}
/**
* 通过block 和 view 得到邮件内容
*/
public static function getSubjectAndBody($block,$viewPath,$langCode='',$params=[]){
if(!$langCode){
$langCode = Yii::$service->store->currentLangCode;
}
if(!$langCode){
Yii::$service->helper->errors->add('langCode is empty');
return ;
}
$bodyViewFile = $viewPath.'/body_'.$langCode.'.php';
$bodyConfigKey = [
'class' => $block,
'view' => $bodyViewFile,
];
if(!empty($params)){
$bodyConfigKey['params'] = $params;
}
$subjectViewFile = $viewPath.'/subject_'.$langCode.'.php';
$subjectConfigKey = [
'class' => $block,
'view' => $subjectViewFile,
];
$emailSubject = Yii::$service->page->widget->render($subjectConfigKey,$parentThis);
$emailBody = Yii::$service->page->widget->render($bodyConfigKey,$parentThis);
return [$emailSubject,$emailBody];
}
/**
* @property $toEmail | String send to email address.
* 客户注册用户发送邮件
*/
public static function sendRegisterEmail($param){
$toEmail = $param['email'];
$registerParam = Yii::$app->getModule('customer')->params['register'];
if(isset($registerParam['email']['enable']) && $registerParam['email']['enable']){
$mailerConfigParam = '';
if(isset($registerParam['email']['mailerConfig']) && $registerParam['email']['mailerConfig']){
$mailerConfigParam = $registerParam['email']['mailerConfig'];
}
if(isset($registerParam['email']['block']) && $registerParam['email']['block']){
$block = $registerParam['email']['block'];
}
if(isset($registerParam['email']['viewPath']) && $registerParam['email']['viewPath']){
$viewPath = $registerParam['email']['viewPath'];
}
if($block && $viewPath){
list($subject,$htmlBody) = self::getSubjectAndBody($block,$viewPath,'',$param);
$sendInfo = [
'to' => $toEmail,
'subject' => $subject,
'htmlBody' => $htmlBody,
'senderName'=> Yii::$service->store->currentStore,
];
//var_dump($sendInfo);exit;
Yii::$service->email->send($sendInfo,$mailerConfigParam);
}
}
}
/**
* 客户登录账号发送邮件
*/
public static function sendLoginEmail($toEmail){
$registerParam = Yii::$app->getModule('customer')->params['login'];
if(isset($registerParam['email']['enable']) && $registerParam['email']['enable']){
$mailerConfigParam = '';
if(isset($registerParam['email']['mailerConfig']) && $registerParam['email']['mailerConfig']){
$mailerConfigParam = $registerParam['email']['mailerConfig'];
}
if(isset($registerParam['email']['block']) && $registerParam['email']['block']){
$block = $registerParam['email']['block'];
}
if(isset($registerParam['email']['viewPath']) && $registerParam['email']['viewPath']){
$viewPath = $registerParam['email']['viewPath'];
}
if($block && $viewPath){
list($subject,$htmlBody) = self::getSubjectAndBody($block,$viewPath);
$sendInfo = [
'to' => $toEmail,
'subject' => $subject,
'htmlBody' => $htmlBody,
'senderName'=> Yii::$service->store->currentStore,
];
Yii::$service->email->send($sendInfo,$mailerConfigParam);
}
}
}
/**
* 客户登录账号发送邮件
*/
public static function sendForgotPasswordEmail($param){
$toEmail = $param['email'];
$forgotPasswordParam = Yii::$app->getModule('customer')->params['forgotPassword'];
$mailerConfigParam = '';
if(isset($forgotPasswordParam['email']['mailerConfig']) && $forgotPasswordParam['email']['mailerConfig']){
$mailerConfigParam = $forgotPasswordParam['email']['mailerConfig'];
}
if(isset($forgotPasswordParam['email']['block']) && $forgotPasswordParam['email']['block']){
$block = $forgotPasswordParam['email']['block'];
}
if(isset($forgotPasswordParam['email']['viewPath']) && $forgotPasswordParam['email']['viewPath']){
$viewPath = $forgotPasswordParam['email']['viewPath'];
}
if($block && $viewPath){
list($subject,$htmlBody) = self::getSubjectAndBody($block,$viewPath,'',$param);
$sendInfo = [
'to' => $toEmail,
'subject' => $subject,
'htmlBody' => $htmlBody,
'senderName'=> Yii::$service->store->currentStore,
];
//var_dump($sendInfo);exit;
Yii::$service->email->send($sendInfo,$mailerConfigParam);
}
}
/**
* 客户联系我们邮件。
*/
public static function sendContactsEmail($paramData){
# 从配置中读出来联系我们的邮件地址。
$contactsParam = Yii::$app->getModule('customer')->params['contacts'];
if(!isset($contactsParam['email']['address']) || ! $contactsParam['email']['address']){
Yii::$service->page->message->addError(['Contact us : receive email is empty , you must config it in Module(Customer):[contacts][email][address]']);
return;
}
$toEmail = $contactsParam['email']['address'];
$mailerConfigParam = '';
if(isset($contactsParam['email']['mailerConfig']) && $contactsParam['email']['mailerConfig']){
$mailerConfigParam = $contactsParam['email']['mailerConfig'];
}
if(isset($contactsParam['email']['block']) && $contactsParam['email']['block']){
$block = $contactsParam['email']['block'];
}
if(isset($contactsParam['email']['viewPath']) && $contactsParam['email']['viewPath']){
$viewPath = $contactsParam['email']['viewPath'];
}
if($block && $viewPath){
$defaultLangCode = Yii::$service->fecshoplang->defaultLangCode;
/**
* 因为contacts 是通过smtp发送给管理员的邮箱地址,因此,这里生成邮件使用默认的语言,而不是当前
* 网店的语言,这样方便管理员阅读内容。
* 在邮件中会标注当前的语言的store langCode。
*/
list($subject,$htmlBody) = self::getSubjectAndBody($block,$viewPath,$defaultLangCode,$paramData);
$sendInfo = [
'to' => $toEmail,
'subject' => $subject,
'htmlBody' => $htmlBody,
'senderName'=> Yii::$service->store->currentStore,
];
Yii::$service->email->send($sendInfo,$mailerConfigParam);
return true;
}
}
/**
* 订阅邮件成功邮件
*/
public static function sendNewsletterSubscribeEmail($param){
# 从配置中读出来联系我们的邮件地址。
$newsletterSubscribeParam = Yii::$app->getModule('customer')->params['newsletterSubscribe'];
$toEmail = $param['email'];
$mailerConfigParam = '';
if(isset($newsletterSubscribeParam['email']['mailerConfig']) && $newsletterSubscribeParam['email']['mailerConfig']){
$mailerConfigParam = $newsletterSubscribeParam['email']['mailerConfig'];
}
if(isset($newsletterSubscribeParam['email']['block']) && $newsletterSubscribeParam['email']['block']){
$block = $newsletterSubscribeParam['email']['block'];
}
if(isset($newsletterSubscribeParam['email']['viewPath']) && $newsletterSubscribeParam['email']['viewPath']){
$viewPath = $newsletterSubscribeParam['email']['viewPath'];
}
if($block && $viewPath){
list($subject,$htmlBody) = self::getSubjectAndBody($block,$viewPath,'',$param);
$sendInfo = [
'to' => $toEmail,
'subject' => $subject,
'htmlBody' => $htmlBody,
'senderName'=> Yii::$service->store->currentStore,
];
//var_dump($sendInfo);exit;
Yii::$service->email->send($sendInfo,$mailerConfigParam);
}
}
}
<body style="background: #F6F6F6; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; margin: 0; padding: 0;">
<div style="background: #F6F6F6; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; margin: 0; padding: 0;">
<table cellspacing="0" cellpadding="0" border="0" height="100%" width="100%">
<tr>
<td align="center" valign="top" style="padding: 20px 0 20px 0">
<table bgcolor="FFFFFF" cellspacing="0" cellpadding="10" border="0" width="650" style="border:1px solid #E0E0E0;">
<tr>
<td valign="top">
<a href="<?= $homeUrl; ?>">
<img src="<?= $logoImg; ?>" alt="" style="margin:10px 0 ;" border="0"/>
</a>
</td>
</tr>
<tr>
<td valign="top">
<h1 style="font-size: 22px; font-weight: normal; line-height: 22px; margin: 0 0 11px 0;">Dear <?= $name ?>,</h1>
<p style="font-size: 12px; line-height: 16px; margin: 0 0 8px 0;">There was recently a request to change the password for your account.</p>
<p style="font-size: 12px; line-height: 16px; margin: 0 0 8px 0;">If you requested this password change, please click on the following link to reset your password: <a href="<?= $resetUrl ?>" style="color:#1E7EC8;"><?= $resetUrl ?></a></p>
<p style="font-size: 12px; line-height: 16px; margin: 0 0 4px 0;">If clicking the link does not work, please copy and paste the URL into your browser instead.</p>
<br />
<p style="font-size:12px; line-height:16px; margin:0 0 8px 0;">If you did not make this request, you can ignore this message and your password will remain the same.</p>
<p style="font-size:12px; line-height:16px; margin:0 0 8px 0;">If you have any questions about your account or any other matter, please feel free to contact us at <a href="mailto:<?= $contactsEmailAddress ?>" style="color:#1E7EC8;"><?= $contactsEmailAddress ?></a> or by phone at <?= $contactsPhone ?>.</p>
</td>
</tr>
<tr>
<td style="background-color: #EAEAEA; text-align: center;"><p style="font-size:12px; margin:0; text-align: center;">Thank you, <strong><?= $storeName; ?></strong></p></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
\ No newline at end of file
<body style="background: #F6F6F6; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; margin: 0; padding: 0;">
<div style="background: #F6F6F6; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; margin: 0; padding: 0;">
<table cellspacing="0" cellpadding="0" border="0" height="100%" width="100%">
<tr>
<td align="center" valign="top" style="padding: 20px 0 20px 0">
<table bgcolor="FFFFFF" cellspacing="0" cellpadding="10" border="0" width="650" style="border:1px solid #E0E0E0;">
<tr>
<td valign="top">
<a href="<?= $homeUrl; ?>">
<img src="<?= $logoImg; ?>" alt="" style="margin:10px 0 ;" border="0"/>
</a>
</td>
</tr>
<tr>
<td valign="top">
<h1 style="font-size: 22px; font-weight: normal; line-height: 22px; margin: 0 0 11px 0;">您好 <?= $name ?>,</h1>
<p style="font-size: 12px; line-height: 16px; margin: 0 0 8px 0;">有一个请求要求更改您帐户的密码。</p>
<p style="font-size: 12px; line-height: 16px; margin: 0 0 8px 0;">如果更改密码请求是由您发起,请点击以下链接重置密码: <a href="<?= $resetUrl ?>" style="color:#1E7EC8;"><?= $resetUrl ?></a></p>
<p style="font-size: 12px; line-height: 16px; margin: 0 0 4px 0;">如果点击链接无效,请将网址复制并粘贴到您的浏览器中。</p>
<br />
<p style="font-size:12px; line-height:16px; margin:0 0 8px 0;">如果您没有发出此请求,则可以忽略此消息,并且您的密码将保持不变。</p>
<p style="font-size:12px; line-height:16px; margin:0 0 8px 0;">如果您对帐户或任何其他问题有任何疑问,请随时与我们联系 <a href="mailto:<?= $contactsEmailAddress ?>" style="color:#1E7EC8;"><?= $contactsEmailAddress ?></a> 或通过电话 <?= $contactsPhone ?>.</p>
</td>
</tr>
<tr>
<td style="background-color: #EAEAEA; text-align: center;"><p style="font-size:12px; margin:0; text-align: center;">谢谢, <strong><?= $storeName; ?></strong></p></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
\ No newline at end of file
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $user common\models\User */
?>
Get <?= Html::encode($name) ?>, message<br/>
Store:"en"<br/>
Email:<?= Html::encode($email) ?><br/>
Mobile:<?= Html::encode($telephone)?><br/>
Content:<?= Html::encode($comment) ?>
\ No newline at end of file
you hava login your account on fecsop!
\ No newline at end of file
<body style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<table cellspacing="0" cellpadding="0" border="0" height="100%" width="100%">
<tr>
<td align="center" valign="top" style="padding:20px 0 20px 0">
<!-- [ header starts here] -->
<table bgcolor="FFFFFF" cellspacing="0" cellpadding="10" border="0" width="650" style="border:1px solid #E0E0E0;">
<tr>
<td valign="top">
<a href="<?= $homeUrl; ?>">
<img src="<?= $logoImg; ?>" alt="" style="margin:10px 0 ;" border="0"/>
</a>
</td>
</tr>
<!-- [ middle starts here] -->
<tr>
<td valign="top">
<h1 style="font-size:22px; font-weight:normal; line-height:22px; margin:0 0 11px 0;"">Dear <?= $name ?>,</h1>
<p style="font-size:12px; line-height:16px; margin:0 0 16px 0;">Welcome to <?= $storeName ?>. To log in when visiting our site just click <a href="<?= $loginUrl ?>" style="color:#1E7EC8;">Login</a> or <a href="<?= $accountUrl ?>" style="color:#1E7EC8;">My Account</a> at the top of every page, and then enter your e-mail address and password.</p>
<p style="border:1px solid #E0E0E0; font-size:12px; line-height:16px; margin:0; padding:13px 18px; background:#f9f9f9;">
Use the following values when prompted to log in:<br/>
<strong>E-mail</strong>: <?= $email; ?><br/>
<strong>Password</strong>: <?= $password; ?><p>
<p style="font-size:12px; line-height:16px; margin:0 0 8px 0;">When you log in to your account, you will be able to do the following:</p>
<ul style="font-size:12px; line-height:16px; margin:0 0 16px 0; padding:0;">
<li style="list-style:none inside; padding:0 0 0 10px;">&ndash; Proceed through checkout faster when making a purchase</li>
<li style="list-style:none inside; padding:0 0 0 10px;">&ndash; Check the status of orders</li>
<li style="list-style:none inside; padding:0 0 0 10px;">&ndash; View past orders</li>
<li style="list-style:none inside; padding:0 0 0 10px;">&ndash; Make changes to your account information</li>
<li style="list-style:none inside; padding:0 0 0 10px;">&ndash; Change your password</li>
<li style="list-style:none inside; padding:0 0 0 10px;">&ndash; Store alternative addresses (for shipping to multiple family members and friends!)</li>
</ul>
<p style="font-size:12px; line-height:16px; margin:0;">If you have any questions about your account or any other matter, please feel free to contact us at <a href="mailto:<?= $contactsEmailAddress ?>" style="color:#1E7EC8;"><?= $contactsEmailAddress ?></a> or by phone at <?= $contactsPhone ?>.</p>
</td>
</tr>
<tr>
<td bgcolor="#EAEAEA" align="center" style="background:#EAEAEA; text-align:center;"><center><p style="font-size:12px; margin:0;">Thank you again, <strong><?= $storeName; ?></strong></p></center></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
\ No newline at end of file
you hava register account on fecsop!
\ No newline at end of file
Get <?= $name ?>, message<br/>
Store:<?= $store ?><br/>
Email:<?= $email ?><br/>
Mobile:<?= $telephone?><br/>
Content:<?= $comment ?>
<body style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<table cellspacing="0" cellpadding="0" border="0" height="100%" width="100%">
<tr>
<td align="center" valign="top" style="padding:20px 0 20px 0">
<!-- [ header starts here] -->
<table bgcolor="FFFFFF" cellspacing="0" cellpadding="10" border="0" width="650" style="border:1px solid #E0E0E0;">
<tr>
<td valign="top">
<a href="<?= $homeUrl; ?>">
<img src="<?= $logoImg; ?>" alt="" style="margin:10px 0 ;" border="0"/>
</a>
</td>
</tr>
<!-- [ middle starts here] -->
<tr>
<td valign="top">
<h1 style="font-size:22px; font-weight:normal; line-height:22px; margin:0 0 11px 0;"">Dear <?= $email ?>,</h1>
<p style="font-size:12px; line-height:16px; margin:0 0 16px 0;">
Your subscribed email was successful, You can click Here to
<a href="<?= $homeUrl ?>"><?= $storeName; ?></a>
, Thank You.
</p>
</td>
</tr>
<tr>
<td bgcolor="#EAEAEA" align="center" style="background:#EAEAEA; text-align:center;"><center><p style="font-size:12px; margin:0;">Thank you again, <strong><?= $storeName; ?></strong></p></center></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
\ No newline at end of file
<body style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<table cellspacing="0" cellpadding="0" border="0" height="100%" width="100%">
<tr>
<td align="center" valign="top" style="padding:20px 0 20px 0">
<!-- [ header starts here] -->
<table bgcolor="FFFFFF" cellspacing="0" cellpadding="10" border="0" width="650" style="border:1px solid #E0E0E0;">
<tr>
<td valign="top">
<a href="<?= $homeUrl; ?>">
<img src="<?= $logoImg; ?>" alt="" style="margin:10px 0 ;" border="0"/>
</a>
</td>
</tr>
<!-- [ middle starts here] -->
<tr>
<td valign="top">
<h1 style="font-size:22px; font-weight:normal; line-height:22px; margin:0 0 11px 0;"">您好 <?= $email ?>,</h1>
<p style="font-size:12px; line-height:16px; margin:0 0 16px 0;">
您的订阅电子邮件已成功,您可以点击此处访问
<a href="<?= $homeUrl ?>"><?= $storeName; ?></a>
, 谢谢。
</p>
</td>
</tr>
<tr>
<td bgcolor="#EAEAEA" align="center" style="background:#EAEAEA; text-align:center;"><center><p style="font-size:12px; margin:0;">再次感谢, <strong><?= $storeName; ?></strong></p></center></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册