使用php的原生mail
函数,这是可行的,但非常困难。 你需要自己实现邮件的多部分协议(要求指定附加头文件并在你的主体中编码你的附件)。
下面是一个多邮件外观的例子(从RFC拍摄)
From: Nathaniel Borenstein <[email protected]>
To: Ned Freed <[email protected]>
Subject: Sample message
MIME-Version: 1.0
Content-type: multipart/mixed; boundary="simple
boundary"
This is the preamble. It is to be ignored, though it
is a handy place for mail composers to include an
explanatory note to non-MIME compliant readers.
--simple boundary
This is implicitly typed plain ASCII text.
It does NOT end with a linebreak.
--simple boundary
Content-type: text/plain; charset=us-ascii
This is explicitly typed plain ASCII text.
It DOES end with a linebreak.
--simple boundary--
This is the epilogue. It is also to be ignored.
这是什么意思,就是你首先需要一个特定的Content-Type头传递到邮件,其中边界值指定邮件中所有部分之间的分隔符(通常,您将有两部分:邮件的实际内容和附件)。
然后在邮件正文中,您需要一个包含所有这些部分的字符串,如上例所示。 如果你想附加二进制文件,事情会变得更加复杂,因为那时你可能需要对这些二进制图像进行base64编码,并将使用的编码添加到已编码的零件头中。总结一下:如果你想要附件,不要使用php mail
函数,而应该使用像PHPMailer这样的工具,它会更高层次,更易于使用。
[用PHP Mail()发送附件的可能的重复?](http://stackoverflow.com/questions/12301358/send-attachments-with-php-mail) – morxa