简体   繁体   中英

send HTML as attachment in email

I'm trying to send an email with an HTML attachment,
I don't want the html to show in the message,
I actually want the file to be attached.

I'm half way there, I have the file attached in the email,
but hotmail is showing the html in the message aswell as attaching it.

I'm using the mime type: application/x-download but have also tried text/html, both have the same result.

Failing the answer to this question, it would be useful if someone knows a file type that can be opened on any computer (except pdf or images) where the source of the file can contain raw/uncompressed text. I'm basically emailing a voucher with the users details filled in onto the voucher, so I'm using str_replace to get them on there and so can't use a pdf with str_replace .

If you are not already don't use PHPs mail() function directly. Use a wrapper class such as SwiftMailer or PHPMailer . They give you far more flexibility and are safer.

As far as generating the voucher I would be most tempted to generate an image with GD if they aren't able to just print the email. This way it will be possible for all users to open it. Some people may not have access to a PDF reader for example.

Is there any reason why they can't just print out the email as the voucher or that you can't just give them a unique voucher number that the can write down? This gives them the greatest flexibility because some customers will not have access to a printer.

If you are using the PHP mail function, you will have to code the ENTIRE email by hand (headers, boundaries, ect) which is annoying and can be difficult to debug.

If you have PEAR installed, they make it extremely easy to do this with the Pear Mail Mime and Pear Mail extensions. They are very simple to use.

If you don't have PEAR installed, there are other wrappers you can use (mentioned in the post by Treffynnon).

如果将内容处置设置为附件,则MUA在用户访问它之前不应显示HTML。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM