Codeigniter电子邮件附件:发送的邮件不带附件

3z6pesqy  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(217)

我在CodeIgniter中发送带有附件的邮件时遇到了一点麻烦。下面是我的代码:

$to="mailtouser@gmail.com"
        $fileUrl=array(base_url()."assets/pdf/sample.pdf", base_url()."assets/pdf/sample1.pdf");
        $subject="TEST MAIL";
        $message="TEST MESSAGE";
        $this->load->library('email');
        $from = "admin@gmail.com;
        $config['wordwrap'] = TRUE;
        $config['mailtype']='html';
        $config['charset'] = 'utf-8';
        $config['priority'] = '2';
        $config['protocol'] = 'sendmail';
        $config['mailpath'] = '/usr/sbin/sendmail';
        $this->email->initialize($config);
        $this->email->set_newline("\r\n");
        $this->email->from($from, 'Little Bloom');
        //$this->email->to();
        if($cc!=''){
            $this->email->cc('sendmail@gmail.com');    
        }
        $this->email->bcc($to);

        $this->email->subject($subject);
        $this->email->message($message);
        if(!empty($fileUrl))
        {
            foreach($fileUrl as $key)
            {  
                $this->email->attach($key);
            }
        }
        return $this->email->send();

有多个pdf文件,所以我正在使用一个数组来保存网址,但当我把这个发送到我的电子邮件功能,这些文件没有附加到邮件。

l3zydbqr

l3zydbqr1#

如果打印数组$fileUrl,您将立即发现问题出在哪里。例如:echo '<pre>'; print_r($fileUrl);die;
URL在your_site和assets之间缺少正斜杠:http://your_siteassets/pdf/sample.pdf
您可以使用以下任一方法解决此问题:

$fileUrl=array(base_url("assets/pdf/sample.pdf"), base_url("assets/pdf/sample1.pdf"));

$fileUrl= array(base_url()."/assets/pdf/sample.pdf", base_url()."/assets/pdf/sample1.pdf");

docs url帮助程序base_url()

相关问题