dongwuwei0718 2016-07-07 13:21
浏览 50

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

I am working in Codeigniter framework. I have written send email code using its email library that looks like below :

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

        $this->email->set_newline("
");

        $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

$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?

  • 写回答

1条回答 默认 最新

  • dongwen3437 2016-07-07 13:36
    关注

    Use this:

    $this->load->library('email', $config);
    
        $this->email->set_newline("
    ");
    
        $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.

    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算