我在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文件,所以我正在使用一个数组来保存网址,但当我把这个发送到我的电子邮件功能,这些文件没有附加到邮件。
1条答案
按热度按时间l3zydbqr1#
如果打印数组$fileUrl,您将立即发现问题出在哪里。例如:
echo '<pre>'; print_r($fileUrl);die;
URL在your_site和assets之间缺少正斜杠:
http://your_siteassets/pdf/sample.pdf
您可以使用以下任一方法解决此问题:
或
docs url帮助程序base_url()