当我使用CI发送带有附件的电子邮件时,没有错误,但发送没有附件和内容。如果发送没有附件电子邮件发送内容。
$this->load->library('email');
$this->email->to('$tomail');
$this->email->cc('$cmail');
$this->email->from('noreply@******8');
$this->email->subject('Gift Voucher');
$this->email->set_mailtype('html');
$data['content'] = 'Please find the attachment.<br> Reach us on : <a href="****">*****</a>';
$data['footer'] = '© ' . date("Y") . '********/ All rights reserved';
$msg = $this->load->view('includes/mail_template', $data, TRUE);
$path = base_url('assets/uploads/giftpurchase/giftvoucher_'.$payid);
$this->email->attach($path);
$this->email->message($msg);
$this->email->send();
答案 0 :(得分:2)
base_url()
为您提供HTTP
路径,您应该使用Directory
路径进行邮件附件
更改
$path = base_url('assets/uploads/giftpurchase/giftvoucher_'.$payid);
// http://www.sitename.com/assets/uploads/giftpurchase/giftvoucher_.....
到
$path = {HERE_ROOT_PATH} 'assets/uploads/giftpurchase/giftvoucher_'.$payid;
// /var/www/html/assets/uploads/giftpurchase/giftvoucher_.....
PS :getcwd()
函数提供当前工作目录,您可以使用它来获取工作dir
路径
$path = getcwd(). 'assets/uploads/giftpurchase/giftvoucher_'.$payid;
答案 1 :(得分:2)
如果您想从您的服务器附加文件您需要使用您的文件系统中的文件路径,而不是来自您的web-root
CodeIgniter中有两个有用的常量:
FCPATH
- &gt;前控制器的路径(顶层index.php
(/system/
上方))
APPPATH
- &gt; /application/
文件夹的路径
$path = FCPATH.'assets/uploads/giftpurchase/giftvoucher_'.$payid;