Hey,
I've made a custom compontent wich mails your own drawings to you. But I have a problem to send an e-mail with attachment.
I use the HttpService to send the data to the php-file, but I always get the Fault message (form phpFault()).
This is my code in Flex:
<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.graphics.codec.PNGEncoder;
import mx.events.ValidationResultEvent;
import mx.controls.Alert;
[Bindable]
private var byteArray:ByteArray;
private function mailImage(comp:DisplayObject):void
{
var emailValidation:ValidationResultEvent = validEmail.validate();
if(emailValidation.type == ValidationResultEvent.INVALID)
{
Alert.show("Invalid E-mail");
}
else
{
var bitmapData:BitmapData = new BitmapData(comp.width, comp.height);
bitmapData.draw(comp);
var png:PNGEncoder = new PNGEncoder();
byteArray = png.encode(bitmapData);
httpMail.send();
}
}
private function phpResult(evt:ResultEvent):void
{
Alert.show("You've got mail.");
}
private function phpFault(evt:FaultEvent):void
{
Alert.show("Something went wrong. /n" + evt.message.toString());
}
]]>
</mx:Script>
<mx:EmailValidator id="validEmail" source="{ipEmail}" property="text"/>
<mx:HTTPService id="httpMail" url="php/byte-receiver.php" method="POST" result="phpResult(event)" fault="phpFault(event)">
<mx:request>
<img>{byteArray}</img>
<mail>{ipEmail.text}</mail>
</mx:request>
</mx:HTTPService>
<mx:Label text="draw your own image" styleName="h1" x="10" y="0" width="493" height="60"/>
<mx:Canvas
id="drawCanvas"
x="10" y="77"
width="561" height="245"
borderStyle="solid" borderColor="#A6A6A6">
</mx:Canvas>
<mx:Label x="10" y="329" text="Your e-mail:" styleName="text"/>
<mx:TextInput
id="ipEmail"
x="86" y="324" width="417"/>
<mx:Label
id="lblMailImage"
x="10" y="383"
text="Mail my image"
click="mailImage(drawCanvas)"
mouseOver="lblMailImage.setStyle('color', '#00067b')"
mouseOut="lblMailImage.setStyle('color', '#717171')"
styleName="button"/>
This is my PHP code
<?php
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = "ImgContact.png"; // Filename that will be used for the file as the attachment
$email_from = "[email protected]"; //Who the email is from
$email_subject = "Contact Winckelmans.net"; // The Subject of the email
$email_message = "Mail send by winckelmans.net. Your drawing is in the attachment"; // Message that the email has in it
$email_to = $_POST['mail']; // Who the email is too
$headers = "From: $email_from";
$data= $_POST['img'];
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message . "\n\n";
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
$mailsend = mail($email_to, $email_subject, $email_message, $headers);
echo $mailsend;
?>
Thanks in advance for your help. Vincent