在 Zend/PHP 中使用电子邮件模板的最佳方式是什么
我正在开发一个用户创建帐户的网站。我需要向许多海洋上的用户发送电子邮件。例如,当注册、忘记密码、订单摘要等时。我想为此使用电子邮件模板。我需要你对此的建议。我想使用一种方法,如果我更改任何电子邮件模板或登录,只需更少的时间和更改。
我考虑过以下方式:
我有一个这样的电子邮件模板表:
id
emailSubject
emailBody
emailType
例如,当用户忘记密码时:
id:
1
emailSubject:
ABC: Link for Password Change
emailBody:
<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>
emailType:
ForgotPassword
准备电子邮件数据:
$emailFields["to"] = "[email protected]";
$emailFields["username"] = "XYZ";
$emailFields["link1"] = "http://abc.com/changepassword?code='123'";
$emailFields["link2"] = "http://abc.com/ignorechangepasswordreq?code='123'";
$emailFields["emailTemplate"] = "ForgotPassword";
现在将所有字段传递给此函数以发送电子邮件:
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打算用上面的方法。您能否建议更好的方法或对上述逻辑进行一些更改。
谢谢。
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 thought about the following way:
I have a table for email templates like this:
id
emailSubject
emailBody
emailType
For example when user forgot password:
id:
1
emailSubject:
ABC: Link for Password Change
emailBody:
<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>
emailType:
ForgotPassword
Prepare email data:
$emailFields["to"] = "[email protected]";
$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.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会使用
Zend_View
。将模板存储在/views/email/EMAILNAME.phtml
中,使用所需的电子邮件模板创建一个Zend_View
对象并向其传递所需的数据。I'd use
Zend_View
. Store your templates in/views/email/EMAILNAME.phtml
, create aZend_View
object with the required email template and pass it the required data.在我的脑海中,未经测试......但类似的东西应该有效:
Off the top of my head, so untested... but something similar should work:
如前所述,
Zend_View
就是这样。我是这样做的:使用 Markdownify 转换为纯文本:
设置邮件:
然后设置传输和发送。
As previously mentioned,
Zend_View
is the way. Here is how I do this:Use Markdownify to covert to plain text:
Setup mail:
Then setup Transport and send.