简体   繁体   English

无法在Codeigniter的电子邮件模板中发送php值

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

I am working in Codeigniter framework. 我在Codeigniter框架中工作。 I have written send email code using its email library that looks like below : 我已经使用其电子邮件库编写了发送电子邮件代码,如下所示:

$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();

And I used $data['content'] in view file as 我在视图文件中使用$ data ['content']作为

$content['first_name']

In view file I send some dynamic value that I want to send in email. 在视图文件中,我发送了一些我想通过电子邮件发送的动态值。 But in mail it gives an error like given variable is not define. 但是在邮件中会给出错误,如给定变量未定义。

So what should I have to do? 那我该怎么办?

Use this: 用这个:

$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();

In your view, Use direct $user_id and so on. 在您看来,请直接使用$user_id等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM