簡體   English   中英

無法在Codeigniter的電子郵件模板中發送php值

[英]Can not send php value in email template in codeigniter

我在Codeigniter框架中工作。 我已經使用其電子郵件庫編寫了發送電子郵件代碼,如下所示:

$this->load->library('email', $config);

        $this->email->set_newline("\r\n");

        $this->email->from('info@webbrainstechnologies.com', 'Instagram Shop');
        $content = array(
                'user_id'       =>$user_id,
                'first_name'    =>$this->input->post('first_name'),
                'last_name'     =>$this->input->post('last_name'),
                'mobile'        =>$this->input->post('mobile_no'),
                'email'         =>$this->input->post('email'),
                'address'       =>$this->input->post('address'),
                'payment_type'  =>$this->input->post('payment_type'),
                'comment'       =>$this->input->post('comment'),
                'order_date'    =>date("Y-m-d h:i:sa")
            );
        $data['content'] = $content;
        $this->email->to($to);  // replace it with receiver mail id
        $this->email->subject("Invoice"); // replace it with relevant subject

        $body = $this->load->view('buyer/invoice',$data,TRUE);
        $this->email->message($body);  
        $this->email->send();

我在視圖文件中使用$ data ['content']作為

$content['first_name']

在視圖文件中,我發送了一些我想通過電子郵件發送的動態值。 但是在郵件中會給出錯誤,如給定變量未定義。

那我該怎么辦?

用這個:

$this->load->library('email', $config);

    $this->email->set_newline("\r\n");

    $this->email->from('info@webbrainstechnologies.com', 'Instagram Shop');
    $data = array(
            'user_id'       =>$user_id,
            'first_name'    =>$this->input->post('first_name'),
            'last_name'     =>$this->input->post('last_name'),
            'mobile'        =>$this->input->post('mobile_no'),
            'email'         =>$this->input->post('email'),
            'address'       =>$this->input->post('address'),
            'payment_type'  =>$this->input->post('payment_type'),
            'comment'       =>$this->input->post('comment'),
            'order_date'    =>date("Y-m-d h:i:sa")
        );

    $this->email->to($to);  // replace it with receiver mail id
    $this->email->subject("Invoice"); // replace it with relevant subject

    $body = $this->load->view('buyer/invoice',$data,TRUE);
    $this->email->message($body);  
    $this->email->send();

在您看來,請直接使用$user_id等。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM