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 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料