首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在Codeigniter中使用URL发送带有附件的电子邮件

在Codeigniter中使用URL发送带有附件的电子邮件
EN

Stack Overflow用户
提问于 2019-06-25 18:30:44
回答 1查看 170关注 0票数 0

我想发一封带附件的电子邮件。

使用文件路径发送电子邮件没有问题,但我更喜欢使用URL设置附件。

该电子邮件可以成功发送到我的电子邮件没有任何附件。

我的PDF URL示例:http://store/index.php/Store/GI/OrderID.pdf

希望有些人能帮到我。真的很感谢。谢谢。

控制器::

代码语言:javascript
复制
    public function SendInvoice(){
        $orderid = $this->uri->segment(3);
        $result = $this->order->GetCustOrder($orderid);

        unset($data);
        $data = array(
                        $OrderID,
                        $result[0]->cust_id,
                        $result[0]->cust_name,
                        $result[0]->cust_email
                      );
        $this->store_email->SendInvoiceToCust($data); //library

        $this->session->set_flashdata('sent_email','Email has been sent to customer.');
        redirect('Store/Index');
    }   

库::

代码语言:javascript
复制
    public function SendInvoiceToCust($data){
        $message = "Dear Valued Customer, <br><br>Thank you for Purchased at Store. <br/><br/>Kindly refer the attachment to view your Invoice.";
        //$attached_file = base_url(). 'index.php/Store/GI/' .$data[0]. '.pdf';
        $form = base_url(). 'index.php/Store/GI/' .$data[0]. '.pdf';
        $attachment = chunk_split(base64_encode($form));

        $separator = md5(time());

        $message .= "--" . $separator . PHP_EOL;
        $message .= "Content-Type: application/octet-stream; name=\"\" . $data[0]. '.pdf'\"" . PHP_EOL;
        $message .= "Content-Transfer-Encoding: base64" . PHP_EOL;
        $message .= "Content-Disposition: attachment" . PHP_EOL . PHP_EOL;
        $message .= $attachment . PHP_EOL . PHP_EOL;
        $message .= "--" . $separator . "--";           

        $this->email->from('email@gmail.com', 'Store');
        $this->email->to('email2@gmail.com'); 

        $this->email->subject('Store INVOICE [Do not reply]');
        $this->email->message($message);
        $this->email->attach($attachment);
        $this->email->send();


    }
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56751996

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档