当前位置: 首页>>代码示例>>PHP>>正文


PHP MailTemplate::findTemplateAndMakeReplacements方法代码示例

本文整理汇总了PHP中MailTemplate::findTemplateAndMakeReplacements方法的典型用法代码示例。如果您正苦于以下问题:PHP MailTemplate::findTemplateAndMakeReplacements方法的具体用法?PHP MailTemplate::findTemplateAndMakeReplacements怎么用?PHP MailTemplate::findTemplateAndMakeReplacements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MailTemplate的用法示例。


在下文中一共展示了MailTemplate::findTemplateAndMakeReplacements方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: mail

    public static function mail($to, $subject, $plaintext_body, $html_body = '', $options = array())
    {
        if (!Helpers::getYiiParam('sendEmails')) {
            return true;
            // we won't send emails if it is not enabled, but we won't fail!
        }
        $from = Helpers::getOption('from', $options, Helpers::getYiiParam('botEmail'));
        if ($from == Helpers::getYiiParam('botEmail')) {
            $sender = Yii::app()->name;
        } else {
            $sender = $from;
        }
        $replyto = Helpers::getOption('replyto', $options, $from);
        $title = $subject;
        $subject = self::b64($subject);
        if (is_array($to)) {
            // we expect an array to be like array('some@example.com'=>'John Doe')
            $address = array_pop(array_keys($to));
            $name = $to[$address];
        } else {
            $name = $address = $to;
        }
        $addressee = self::b64($name) . " <" . $address . ">";
        $headers = array('From: ' . self::b64($sender) . " <{$from}>", "Reply-To: {$replyto}", 'MIME-Version: 1.0', "X-SWU-Version: " . SWU::RELEASE);
        foreach (array('message_id' => 'Message', 'originating_IP' => 'Originating-IP') as $key => $value) {
            if ($info = Helpers::getOption($key, $options, false)) {
                $headers[] = 'X-SWU-' . $value . ': ' . $info;
            }
        }
        $ack = Helpers::getOption('ack', $options, false);
        $ack_link = $ack ? Yii::app()->getController()->createAbsoluteSslUrl('message/ack', array('k' => Helpers::generateAckKey($ack['message_id']))) : false;
        $ack_image = Yii::app()->getController()->createAbsoluteSslUrl('site/image', array('name' => 'swu', 'k' => Helpers::generateAckKey(Helpers::getOption('message_id', $options))));
        $htt = new MailTemplate();
        $htt->findTemplateAndMakeReplacements('standard_head', array('title' => $subject, 'ack_link' => $ack_link, 'ack_image' => $ack_image));
        list($plaintext_head, $html_head) = array($htt->getSubtemplateField('plaintext_body'), $htt->getSubtemplateField('html_body'));
        $htt->findTemplateAndMakeReplacements('standard_tail', array('ack_link' => $ack_link, 'ack_image' => $ack_image));
        list($plaintext_tail, $html_tail) = array($htt->getSubtemplateField('plaintext_body'), $htt->getSubtemplateField('html_body'));
        if ($html_body) {
            //create a boundary string. It must be unique
            //so we use the MD5 algorithm to generate a random hash
            $random_hash = md5(date('r', time()));
            //add boundary string and mime type specification
            $headers[] = "Content-Type: multipart/mixed; boundary=\"PHP-mixed-{$random_hash}\"";
            $html = quoted_printable_encode($html_head . $html_body . $html_tail);
        }
        $plaintext_body = quoted_printable_encode($plaintext_body);
        if ($html_body) {
            $body = <<<EOT
--PHP-mixed-{$random_hash}  
Content-Type: multipart/alternative; boundary="PHP-alt-{$random_hash}" 

--PHP-alt-{$random_hash}  
Content-Type: text/plain; charset="UTF-8" 
Content-Transfer-Encoding: quoted-printable

{$plaintext_body}

--PHP-alt-{$random_hash}  
Content-Type: text/html; charset="UTF-8" 
Content-Transfer-Encoding: quoted-printable

{$html} 

EOT;
        } else {
            $headers[] = "Content-type: text/plain; charset=UTF-8";
            $headers[] = "Content-Transfer-Encoding: quoted-printable";
            $body = $plaintext_body;
        }
        Yii::log('sending message to ' . $addressee, 'info', 'components.Mailer');
        try {
            if (mail($addressee, $subject, $body, implode("\r\n", array_merge($headers, Helpers::getYiiParam('customMailHeaders'))) . "\r\n")) {
                return true;
            }
        } catch (Exception $e) {
            Yii::log('failed sending message to ' . $addressee . ' ' . $e->getMessage(), 'error', 'components.Mailer');
            return false;
        }
        return false;
    }
开发者ID:loristissino,项目名称:swu,代码行数:80,代码来源:Mailer.php


注:本文中的MailTemplate::findTemplateAndMakeReplacements方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。