带有附件的Codeigner电子邮件不起作用



我在堆栈溢出上检查过类似的链接。但我找不到任何解决方案。

链接的我已检查

  1. Codeigniter发送带有附加文件的电子邮件
  2. 代码点火器->附加电子邮件
  3. codeigniter将pdf文件作为电子邮件附件发送

问题

当我发送邮件时,我会收到邮件。所有细节。但连接不起作用。

尝试

我回显文件名,它从控制器打印文件名

代码

$upcon['upload_path'] = 'cv_uploads/';
$upcon['max_size'] = '5120';
$upcon['allowed_types'] = 'pdf|doc|txt|zip|rtf|docx';
$this->load->library('upload', $upcon);
if(!$this->upload->do_upload('file')){
    echo $this->upload->display_errors();
}
else{
    $up_data = $this->upload->data();
    $config['protocol'] = 'sendmail';
    $config['mailpath'] = '/usr/sbin/sendmail';
    $config['mailtype']  = 'html';
    $config['charset'] = 'iso-8859-1';
    $config['wordwrap'] = TRUE;
    $this->load->library('email',$config);
    $this->email->set_newline("rn");
    $name = $this->input->post('name');
    $email = $this->input->post('email');
    $address = $this->input->post('address');
    $residence = $this->input->post('residence');
    $office = $this->input->post('office');
    $mobile = $this->input->post('mobile');
    $position = $this->input->post('position');
    $comment = $this->input->post('comment');
    $file_name= '/cv_uploads/'.$up_data['file_name'];
    $this->email->from('xx@xxx.com', 'site name'); 
    $this->email->to('yy@yyyy.com');
    $this->email->attach($file_name);
    $this->email->subject('Subject');
    $this->email->message("Message ");
    if(!$this->email->send())
    {
        $data['sent_mail'] = false;
    }
    else{
        $data['sent_mail'] = "true";
    }
    print_r($file_name);
}

我收到的邮件没有附件。知道吗??

要发送附件,请使用绝对路径而不是相对路径,并确保附件可供公众访问。

绝对路径示例

c:/test/test/cv_uploads/cv.doc

在你的代码中尝试

$file_name= FCPATH.'/cv_uploads/'.$up_data['file_name'];

$file_name= $_SERVER["DOCUMENT_ROOT"].'/cv_uploads/'.$up_data['file_name'];

并附加具有此功能的文件

$this->email->attach($file_name);

相关内容

  • 没有找到相关文章

最新更新