Emailing images directly from Flash with PHP

For an interactive drawing project I worked on recently I needed to provide the ability for users to email their artwork directly from the app without the need to save any images to a server. I pieced together a solution from various blogs and websites and I decided to provide the full source here.

The function below takes an encoded bitmapdata and an email address and sends them to the PHP script further down in this post. The bytearray passed in must be encoded as a JPG – you can use any of the available encoders such as CoreLib, Faster JPG Encoder, or the Alchemy Encoder.