电子邮件不会与ci中的附件一起发送

时间:2014-08-07 12:26:44

标签: php codeigniter email

当我使用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'] = '&copy; ' . 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();

2 个答案:

答案 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;