dongtiaozhou4914 2014-01-17 01:21
浏览 16
已采纳

我正在尝试创建和html页面作为电子邮件的正文。 如何使用yiiMail将其传递给我的setBody()?

I have a .php page with the following code:

 <html>
<head></head>
<body>
    Hi <?php echo $user['first_name'].' '.$user['last_name']?>,
    <br><br>
    To reset your password, please go to the following page:
    <br>
    <?php 
            $url = Yii::app()->createAbsoluteUrl('user/reset/id/'.  $key);
            echo "<a href='{$url}'>{$url}</a>";
    ?>
    <br>
    Your password will be automatically reset, and a new password will be emailed to you.        
</body>

I want to be able to put this inside a function I created in the Controller inside setBody() here:

  public function emailAll($url)
    {

        $this->set_mail_settings();
        $message = new YiiMailMessage;        

            $emails = Yii::app()->db->createCommand("SELECT group_concat(email) as em FROM persons WHERE party_id != 184")->queryRow();
            $email_ids = explode(",",$emails["em"]);
            $message->setBcc($email_ids);
            $message->setBody('To view, click here: '.$url);
            $message->subject = 'New Announcement Posted!';
            $message->addTo('dcp@gmail.com');
            $message->from = Yii::app()->params['adminEmail'];
            Yii::app()->mail->send($message);                      
    }

The URL link that I want inside the body is coded from the actionCreate() which is here:

 $currentid = Yii::app()->db->createCommand("select id from content where id = (select max(id) from content)")->queryRow();
                Yii::app()->session['announcement_message'] = 'You have successfully created an announcement.';

                $url = Yii::app()->createAbsoluteUrl('announcement/view/id/'.  $currentid["id"]);

                $this->emailAll($url);

                $this->redirect(array('view','id'=>$model->id));

I'm just now trying to figure out how I would send that .php page that has html inside into the setBody() along with $url I passed. Any help?

  • 写回答

1条回答 默认 最新

  • dsceme82487 2014-01-17 05:29
    关注

    To do this, you store the mail template .php file as a view in your corresponding view folder, then call

    $message->setBody(
        $this->renderPartial("_yourTemplateFileName",
                 array("key"=>$key,'user'=>$user),true,false)
     );
    

    RenderPartial can process a file and return the output by setting the third parameter return as true, the fourth parameter is for processing Js stuff not required in this context.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件
  • ¥15 使用ESP8266连接阿里云出现问题