【问题标题】:Codeigniter email with attachment not working带附件的 Codeigniter 电子邮件不起作用
【发布时间】:2016-07-15 15:24:23
【问题描述】:

我已经检查了关于堆栈溢出的类似链接。但是我找不到任何解决方案。

我已检查的链接

  1. Codeigniter send email with attach file
  2. Code Igniter -> attach email
  3. codeigniter send pdf file as email attachment

问题

什么时候发送邮件,我收到邮件。与所有细节。但附件不起作用。

试试

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

代码

$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("\r\n");

    $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);
}

我收到的邮件没有附件。有什么想法吗??

【问题讨论】:

标签: php codeigniter email email-attachments


【解决方案1】:

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

绝对路径示例

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);

【讨论】:

  • sry 是复制粘贴错误
  • 没有。在线的。我收到邮件。只有附件挂起
  • 任何存储在 cv_uploads 中的文件名
  • 试试这个 $this->email->attach("americanwater.lk/cv_uploads/CV.pdf") @CILearn
  • 没有。它不工作。只是邮件来我就是这样。没有文件
猜你喜欢
  • 1970-01-01
  • 2015-11-03
  • 2014-07-05
  • 1970-01-01
  • 2015-06-06
  • 2017-10-21
  • 1970-01-01
  • 1970-01-01
  • 2015-12-29
相关资源
最近更新 更多