使用imap函数向已发送邮件添加附件

I use the imap php functions for smtp mailbox. When I send mail with multiple attachments, any file using imap_mail() function will be properly sent with all attachments. But my view it in my Sent Items box, all mail text shows, but the attachment file shows up as a text file - not as a actual file.

I use the same header code for the sent imap_mail() function and imap_append() function. Why is this unexpected behavior happening?

This is likely to be an encoding problem.

There are several parts you send as mail.

For example:

The Body Part:

"Content-Type: text/html; charset="iso-8859-1"
"Content-Transfer-Encoding: 7bit"
...  

 
The Attachment Part (a jpeg image for example):

"Content-Type: image/jpg; name="attachment_1.jpg"
"Content-Transfer-Encoding: base64"
"Content-disposition: attachment; file="attachment_1.jpg"

chunk_split(base64_encode($file)) // PHP function to base64 encode the file
...

There are lots of tutorials out there. Just Google them and pick the one that suits your experience level.

 
Furthermore I'd like to recommend you to start using something like SwiftMailer instead of PHP's native mail, as mails sent with mail() are placed into the spam folder with most popular mail providers like GMail etc. The mailer class also provides a broader amount of adjustable functionality especially for adjustments.

 
Have a look in the docs here:
http://swiftmailer.org/docs/messages.html#attaching-files

Also check out this specific answer on StackOverflow:
https://stackoverflow.com/a/4671714/2493918

Good luck!

Thanks for this but in to this link https://stackoverflow.com/a/4671714/2493918 i seen Swift_Connection_SMTP(MAIL_SMTP_URL, MAIL_SMTP_PORT) function. but i don't understand where i put email id and password into this function paremeter for smtp connection.