2011-11-17 48 views

回答

2

附件使用多部分电子邮件格式。你最好使用一些库来做到这一点。但是,如果你想管理它自己,你需要创建一个由多bounaries分隔的文件,这个文件包含base64编码文件:

首先,电子邮件标题:

To: [email protected] 
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

+0

感谢您的回答! 我正在尝试。 – leapkh

+0

我的项目需要使用PEAR中的Net_IMAP。在那个库中,函数Net_IMAP :: appendMessage($ rfc_message)只需要$ rfc_message。我认为rfc_message包含header和body在一个。问题是我仍然无法构建像这样的消息。 Pleaase帮助我! – leapkh

+0

正如我在文档中看到的,appendMessage返回“Pear_Error”对象。尝试'var_dump'它。我的意思是:'$ n = new Net_IMAP(...你的参数在这里...); ... var_dump($ n-> appendMessage(...));' – Oroboros102

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();