开发者

CakePHP send email with recent post url

开发者 https://www.devze.com 2023-03-13 02:43 出处:网络
I am trying to send an email from a CakePHP controller with the url of the current post thats being added. I need to find the id of the post so it can pass it to the view function but i wont know that

I am trying to send an email from a CakePHP controller with the url of the current post thats being added. I need to find the id of the post so it can pass it to the view function but i wont know that?

Ie.

    function add() {
        if (!empty($this->data)) {
            //var_dump($this->data);
            //die();
        开发者_运维百科    $file_path = $this->Attachment->upload($this->data['Post'],'img');
            //$this->Attachment->thumbnail($this->data['Post']['img'], 'attachments/files_dir', '250', '250', $crop = 'resize');
            if ($this->Post->save($this->data)) {
                $this->sendTemplateHtmlMail();
                $this->Session->setFlash('Your post has been saved.');
                $this->redirect(array('action' => 'index'));
            }
        }
    }

    function sendTemplateHtmlMail($recipientemail, $to) { 
        $this->Email->to = 'test@gmail.com'; 
        $this->Email->subject = 'Cake test template email'; 
        $this->Email->replyTo = 'noreply@example.com'; 
        $this->Email->from = 'Cake Test Account <noreply@example.com>'; 
        $this->Email->template = 'test2'; 
        //Send as 'html', 'text' or 'both' (default is 'text') 
        $this->Email->sendAs = 'html'; 
        //Set view variables as normal 
        $this->set('recipientemail', ); 
        //Do not pass any args to send() 
        if ( $this->Email->send() ) { 
            $this->Session->setFlash('Template html email sent'); 
        } else { 
            $this->Session->setFlash('Template html email not sent'); 
        } 
//        $this->redirect('/'); 

    } 

so i'm adding/saving a post and then sending an email to the recipient, in the email i want the url of the just added post, how do i pass the id of the post if i dont know it yet?

Thanks


$this->Post->id will contain the last inserted id. Is that what you were looking for?

0

精彩评论

暂无评论...
验证码 换一张
取 消