我有一个 Codeigniter 3.1.4 网站,在托管公司更改其电子邮件主机之前一直运行良好。
我从我的网站发送附有 PDF 的电子邮件,但 smtp 提供商已更改,并且我更新了以下值:
defined('PROTOCOL') OR define('PROTOCOL', 'mail');
defined('SMTP_HOST') OR define('SMTP_HOST', 'smtp.titan.email');
我的代码:
public function emailPDF ($id) {
$timesheet = $this->timesheets_model->get_timesheets($id)[0];
$filename = $this->getFilename($id);
$master_company = 'company';
$companyname = 'companyname';
$this->load->library('email');
$config['protocol'] = 'mail';
$config['smtp_host'] = 'smtp0101.titan.email';
$config['smtp_user'] = SMTP_USER;
$config['smtp_pass'] = SMTP_PASS;
$config['smtp_port'] = 465;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailpath'] = MAILPATH;
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
$this->email->from($master_company->email);
$this->email->to("{$company->email}");
$filename = PDF_PATH . $filename;
chmod($filename, 777);
$this->email->attach($filename, 'attachment');
$this->email->subject("Service Sheet for $companyname");
$this->email->message("Hi,<br><br> Please find attached a Service Sheet");
if($this->email->send()) {
$this->session->set_flashdata('level', 'success');
// if ($this->timesheets_model->set_email_sent($id)) {
// $this->session->set_flashdata('message', 'Email sent successfully');
// }
} else {
//show_error($this->email->print_debugger());
$this->session->set_flashdata('message', 'There was a problem sending the email');
$this->session->set_flashdata('level', 'danger');
}
}
电子邮件仍会发送,但不再附加 PDF,而是内联添加。
Content-Type: multipart/alternative; boundary="B_ALT_662fa8a442c93"--B_ALT_662fa8a442c93
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bitHi, Please find attached a Service Sheet for your company. Please do not reply to this email address as this account is not monitored.Regards
--B_ALT_662fa8a442c93
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printableHi,=3Cbr=3E=3Cbr=3E Please find attached a Service Sheet for your company=3Cbr=3E=3Cbr=3EPlease do not reply to this email addr=
ess as this account is not monitored.=3Cbr=3E=3Cbr=3ERegards,=3Cbr=3E.--B_ALT_662fa8a442c93--
Content-Type: application/pdf; name="your+company-2024-04-29-090529-Alarm.pdf"
Content-Disposition: inline;
Content-Transfer-Encoding: base64JVBERi0xLjMKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZwovT3V0bGluZXMgMiAwIFIKL1BhZ2Vz
...
我尝试将
$this->email->attach($filepath, 'inline');
更改为 $this->email->attach($filepath, 'attach');
png 的情况也是如此
没有运气
很明显,PDF 附件内容正在合并到电子邮件文本本身中,但我能看到的唯一可能影响这一点的配置项是:
$config['newline'] = "\r\n";
但据报道,不将此值括在双引号中可能会导致问题,但在我的情况下,双引号是问题所在,将它们括在单引号中修复了它!