在 Zend/PHP 中使用电子邮件模板的最佳方式是什么 [英] What is the best way to use Email Template in Zend/PHP

查看:26
本文介绍了在 Zend/PHP 中使用电子邮件模板的最佳方式是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个网站上工作,用户可以在其中创建他们的帐户.我需要向大洋彼岸的用户发送电子邮件.例如,在注册、忘记密码、订单摘要等时.我想为此使用电子邮件模板.我需要你的建议.我想使用一种方式,如果我更改任何电子邮件模板或在更短的时间内登录和更改.

I am working on a website where Users create their accounts. I need to send email to users on many oceans. For example when signup, forgot password, order summary etc. I want to use emails templates for this. I need your suggestions for this. I want to use a way that If I change any email template or login in less time and changes.

我想过以下方法:

我有一个像这样的电子邮件模板表:

I have a table for email templates like this:

id
emailSubject
emailBody
emailType

例如当用户忘记密码时:

For example when user forgot password:

标识:

1

电子邮件主题:

ABC: Link for Password Change

电子邮件正文:

<table border=0>
<tr><td>
   <b> Dear [[username]] <b/>
</td></tr>

<tr><td>
   This email is sent to you in response of your password recovery request. If you want to change your password, please click the following link:<br />
[[link1]]
<br/>
If you don't want to change your password then click the following link:<br/>
[[link2]]
</tr></td>

<tr><td>
   <b>ABC Team</b>
</td></tr>

</table>

电子邮件类型:

ForgotPassword

准备电子邮件数据:

$emailFields["to"] = "user@abc.com";
$emailFields["username"] = "XYZ";
$emailFields["link1"] = "http://abc.com/changepassword?code='123'";
$emailFields["link2"] = "http://abc.com/ignorechangepasswordreq?code='123'";
$emailFields["emailTemplate"] = "ForgotPassword";

现在将所有字段传递给此函数以发送电子邮件:

Now Pass the all fields to this function to send email:

sendEmail( $emailFields ){
 // Get email template from database using emailTemplate name.
 // Replace all required fields(username, link1,link2) in body.
 // set to,subject,body
 // send email using zend or php
}

我打算使用上述方法.您能否提出更好的方法或对上述逻辑进行一些更改.

I planed to use above method. Can you suggest better way or some change in above logic.

谢谢.

推荐答案

我会使用 Zend_View.将您的模板存储在 /views/email/EMAILNAME.phtml 中,使用所需的电子邮件模板创建一个 Zend_View 对象并将所需的数据传递给它.

I'd use Zend_View. Store your templates in /views/email/EMAILNAME.phtml, create a Zend_View object with the required email template and pass it the required data.

这篇关于在 Zend/PHP 中使用电子邮件模板的最佳方式是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆