通过 Codeigniter 发送带附件的电子邮件时出错
Posted
技术标签:
【中文标题】通过 Codeigniter 发送带附件的电子邮件时出错【英文标题】:Error while sending email with attachment through Codeigniter 【发布时间】:2020-01-12 08:39:41 【问题描述】:我正在尝试通过 Codeigniter 发送带有附件的电子邮件。问题是它在运行时附加了文件,但只是发送了指定的内容而忽略了附件。
我已尝试将其上传到“上传”文件夹并将其与内容一起发送,但它仅发送消息并显示下面提到的错误
类 Email_send 扩展 CI_Controller
public function send()
$file_data = $this->upload_file();
$to = $this->input->post('from'); // User email pass here
$subject = 'Offer from Saremco Impex';
$from = 'myemail';// Pass here your mail id
$emailContent = '<!DOCTYPE><html><head></head><body><table style="border:1px solid #cccccc;margin: auto;border-spacing:0;"><tr><td style="background:#ffa500;padding-left:3%"><!--<img src="http://localhost/crud/assets/logo/eoffice_logo.png" vspace=10 />--></td></tr>';
$emailContent .= '<tr><td style="height:20px"></td></tr>';
$emailContent .= $this->input->post('message'); // Post message available here
$emailContent .= '<tr><td style="height:20px"></td></tr>';
$emailContent .= "<tr><td style='background:#ffa500;color: #999999;padding: 2%;text-align: center;font-size: 13px;'><p style='margin-top:1px;'><a href='http://saremcoimpex.com/' target='_blank' style='text-decoration:none;color: #60d2ff;'>www.saremcoimpex.com</a></p></td></tr></table></body></html>";
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = 465;
$config['smtp_timeout'] = 60;
$config['smtp_user'] = 'myusername';
$config['smtp_pass'] = 'mypass';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'html'; // or html
$config['validation'] = FALSE; // bool whether to validate email or not
//$file_path = 'uploads/' . $file_name;
$this->load->library('email', $config);
$this->email->initialize($config);
$this->email->set_mailtype("html");
$this->email->from($from);
$this->email->to($to);
$this->email->subject($subject);
$this->email->message($emailContent);
$this->email->attach($file_data['full_path']);
$this->email->send();
/* $this->session->set_flashdata('success','Mail has been sent successfully');
return redirect(base_url().'index.php/user/');*/
echo $this->email->print_debugger();
function upload_file()
$config['upload_path'] = './uploads';
$config['allowed_types'] = 'doc|docx|pdf';
$this->load->library('upload', $config);
if($this->upload->do_upload('resume'))
return $this->upload->data();
else
return $this->upload->display_errors();
消息:非法字符串偏移 'full_path' 这就是错误
【问题讨论】:
【参考方案1】:从技术上讲,这应该可行。也许您的上传工作不正常,如果 display_errors() 返回一个字符串,那将是您的错误的原因。
【讨论】:
以上是关于通过 Codeigniter 发送带附件的电子邮件时出错的主要内容,如果未能解决你的问题,请参考以下文章