使用php mail()函数发送电子邮件附件 - 为gmail工作但附件的大小为0(0字节),适用于yahoo

时间:2015-02-26 09:54:58

标签: php email email-attachments ymail

我使用php mail()函数发送带附件的电子邮件。

它适用于gmail,但雅虎的附件大小为零(0字节)。

以下是我使用的附件代码:

                $xMessage .= "Content-type:text/html; charset=iso-8859-1\r\n";
                $xMessage .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
                $xMessage .= $message."\r\n\r\n";

                $xMessage .= "--".$mime_boundary."\r\n";

                $xMessage .= "Content-Type: application/octet-stream; name=\"".basename("uploads/attachment_file/".$file['attachment_name'])."\"\r\n";

                $xMessage .= "Content-Transfer-Encoding: base64\r\n";

                $xMessage .= "Content-Disposition: attachment; filename=\"".basename("uploads/attachment_file/".$file['attachment_name'])."\"\r\n";

                $content = file_get_contents("uploads/attachment_file/".$file['attachment_name']);

                $xMessage.= chunk_split(base64_encode($content));

                $xMessage .= "\r\n\r\n";

我还应该如何在雅虎获取附件?

1 个答案:

答案 0 :(得分:-1)

将/ r / n更改为

$eol = PHP_EOL;

并更改

"Content-Disposition: attachment; filename=\"".basename("uploads/attachment_file/".$file['attachment_name'])."\"\r\n";

"Content-Disposition: attachment; filename=\"".basename("uploads/attachment_file/".$file['attachment_name']).$eol.$eol;