如何使用附件创建RFC邮件格式?

时间:2011-11-17 08:31:41

标签: php pear

我在创建带附件的RFC邮件格式时遇到问题。请帮我! 感谢

2 个答案:

答案 0 :(得分:2)

附件以多部分电子邮件格式制作。你最好用一些lib来做。但是如果你想自己管理它,你需要创建一个由多部分bounaries分隔的文档,其中包含base64编码的文件:

首先,电子邮件标题:

To: admin@example.com
Subject: hi, admin!
Content-Type: multipart/alternative; boundary="some_random_string"

比身体:

This is a multi-part message in MIME format.
some_random_string
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
<p>Email text and image</p>
<img src="cid:attached_image">

some_random_string
Content-Type: image/png;name="some.png"
Content-Transfer-Encoding: base64
Content-ID: <attached_image> //<- this used in CID
Content-Disposition: inline; filename="some.png"
//here goes base64 encoded image.

php.net中有一些示例函数。在评论中查看here

答案 1 :(得分:0)

我更喜欢使用phpmailer库,它是免费的,可供下载。这些内容可以帮助你。

require_once("PHPMailer.class.php");                                                                $mail=  new PHPMailer();                                                                               $mail->IsHTML(true); 


                $mail->Host ='Your Hostname';
                $mail->AddAddress($clientaddress);

                $mail->From = $email;
                $mail->FromName = $name;
                $mail->Subject = "Your Subject";
                $mail->AddAttachment($path);
                $mail->Body=$msg;       

                $mail->Send();
相关问题