【问题标题】:PHP - mail with attachments - message not showingPHP - 带有附件的邮件 - 消息未显示
【发布时间】:2015-09-09 08:18:25
【问题描述】:

我正在尝试完成发送带有附件的邮件

问题:发送的电子邮件没有邮件正文和附件

目标:发送utf-8html带附件的电子邮件

到目前为止我已经创建...

用法:

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}";

删除"--"

最后一个正文部分之后的封装边界是一个可区分的分隔符,表示后面不会有其他正文部分。

【问题讨论】:

  • 乍一看,您的脚本在我看来还不错...您是否尝试过发送不带附件的电子邮件?

标签: php email attachment


【解决方案1】:

处理多部分消息时,您需要在--==MIME_BOUNDARY! 之前用两个 换行符分隔每个部分(消息正文+ 附件)!否则,它们不会在您的消息中正确分开。

只需将\n 添加到您现有的代码中:

$this->body[] = $this->message."\n\n";
...
$this->body[] = "{$a['data']}\n\n";

免责声明:我没有测试过这些,希望它有效。

欲了解更多信息,请查看RFC 1521

【讨论】:

    【解决方案2】:

    当心https://bugs.php.net/bug.php?id=68776 - 不再允许多个换行符,对我来说,DOOManiac 的答案不起作用(不再)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-03
      • 2015-08-29
      • 1970-01-01
      相关资源
      最近更新 更多