4

私はユーザーが自分のアカウントを作成するウェブサイトで働いています。多くの海のユーザーにメールを送信する必要があります。たとえば、サインアップするとき、パスワードを忘れたとき、注文の概要など。これにはメールテンプレートを使用したいと思います。これについてのあなたの提案が必要です。メールテンプレートを変更したり、ログイン時間と変更を短縮したりする方法を使用したいと思います。

私は次のように考えました:

次のようなメールテンプレートの表があります。

id
emailSubject
emailBody
emailType

たとえば、ユーザーがパスワードを忘れた場合:

id:

1

メールの件名:

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"] = "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";

次に、すべてのフィールドをこの関数に渡して、電子メールを送信します。

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
}

上記の方法を使用する予定でした。上記のロジックのより良い方法またはいくつかの変更を提案できますか?

ありがとう。

4

3 に答える 3

8

私は使用しますZend_View。テンプレートをに保存し、必要なメールテンプレートを/views/email/EMAILNAME.phtml使用してオブジェクトを作成しZend_View、必要なデータを渡します。

于 2010-03-10T11:05:18.763 に答える
5

私の頭のてっぺんから、テストされていないので...しかし、同様の何かが機能するはずです:

$view = new Zend_View();
$view->setScriptPath( '/path/to/your/email/templates' );
$view->assign( $yourArrayOfEmailTemplateVariables );
$mail = new Zend_Mail();
// maybe leave out phtml extension here, not sure
$mail->setBodyHtml( $view->render( 'yourHtmlTemplate.phtml' ) );
$mail->setBodyText( $view->render( 'yourTextTemplate.phtml' ) );
于 2010-03-10T11:54:03.440 に答える
0

前に述べZend_Viewたように、それが方法です。これが私がこれを行う方法です:

$template = clone($this->view);
$template->variable = $value;
$template->myObject = (object)$array;
// ...
$html = $template->render('/path/filename.phtml');

Markdownifyを使用して、プレーンテキストに変換します。

$converter = new Markdownify_Extra;
$text = $converter->parserString($html);

セットアップメール:

$mail = new Zend_Mail();
$mail->setBodyHtml($html);
$mail->setBodyText($text);

次に、トランスポートを設定して送信します。

于 2010-03-10T18:46:30.393 に答える