我正在尝试完成发送带附件的邮件
问题:电子邮件发送时没有邮件正文和附件
目标:发送带有附件的utf-8
html
个电子邮件
我到目前为止创造了......
用法:
email_library.php
<?php
private function create_body()
{
$this->body[] = "--{$this->uid}";
$this->body[] = "Content-type: text/html; charset=utf-8";
$this->body[] = "Content-Transfer-Encoding: 7bit";
$this->body[] = $this->message;
if (!empty($this->attachments)) {
foreach ($this->attachments as $k => $a) {
$this->body[] = "--{$this->uid}";
$this->body[] = "Content-Type: application/octet-stream; name=\"{$a['name']}\"";
$this->body[] = "Content-Description: {$a['name']}";
$this->body[] = "Content-Transfer-Encoding: base64";
$this->body[] = "Content-Disposition: attachment; filename=\"{$a['name']}\"";
$this->body[] = "{$a['data']}";
}
}
$this->body[] = "--{$this->uid}--";
}
编辑:
$this->body[] = "--{$this->uid}";
删除"--"
最后一个身体部位后面的封装边界是一个区别分隔符,表示不会跟随其他身体部位。
答案 0 :(得分:1)
使用多部分邮件时,您需要在--==MIME_BOUNDARY
之前使用两个换行符分隔每个部分(邮件正文+附件)!否则,它们不会在您的消息中正确分开。
只需将\n
添加到现有代码中:
$this->body[] = $this->message."\n\n";
...
$this->body[] = "{$a['data']}\n\n";
免责声明:我没有对此进行任何测试,希望它有效。
有关详细信息,请查看RFC 1521
答案 1 :(得分:0)
注意https://bugs.php.net/bug.php?id=68776 - 不再允许多个换行符,对我来说DOOManiac的答案不再有用了。