我希望我的访问者能够将我的应用程序中的创作作为附件发送给朋友(就像创作的屏幕截图)。我可以让 Flex 和 PHP 进行通信并发送电子邮件,但我无法让图像发送。它发送一个 2o 或更小的附件并且无法打开(当然!)。
我的应用程序没有返回错误
我发现下面链接的这些帖子对我有帮助,但我仍然不知道如何将图像从 Flex 传递到 PHP。
- 将整个 Flash 文档以 JPEG 格式保存到电子邮件作为附件
- https://stackoverflow.com/questions/2266284/sending-an-e-mail-with-attachment-with-php-from-flex
这是我来自 Flex 的代码:
private function sendMail():void{
var _nomSTF:String = nomSTF.text;
var _emailSTF:String = emailSTF.text;
var _emailFriendSTF:String = emailFriendSTF.text;
var _sujetSTF:String = sujetSTF.text;
var _messageSTF:String = messageSTF.text;
//IMAGE
var fr:FileReference = new FileReference();
var encoder:PNGEncoder = new PNGEncoder();
var screenshotData:BitmapData = new BitmapData(conteneurDeMonImage.width, conteneurDeMonImage.height, true, 0xFFFFFF);
screenshotData.draw(conteneurDeMonImage);
//var outputData:ByteArray = encoder.encode(screenshotData);
//var base64:Base64Encoder = new Base64Encoder();
var png:PNGEncoder = new PNGEncoder();
byteArray = png.encode(screenshotData);
//base64.encodeBytes(outputData);
//FIN IMAGE
var evValidMail:ValidationResultEvent = emailSTFValidator.validate();
var evValidMailFriend:ValidationResultEvent = emailFriendSTFValidator.validate();
var evValidName:ValidationResultEvent = nomSTFValidator.validate();
if (evValidMail.type == ValidationResultEvent.VALID
&& evValidName.type == ValidationResultEvent.VALID
&& evValidMailFriend.type == ValidationResultEvent.VALID){
emailService.send({senderName: _nomSTF, senderEmail:_emailSTF, emailFriendSTF: _emailFriendSTF,
emailSubject:_sujetSTF, emailMessage: _messageSTF, file : byteArray});
} else {
resultLabel.text="There are Form errors";
resultLabel.setStyle("styleName", "invalid");
}
}
private function emailResultSTF():void{
Alert.show("Votre message a bien été envoyé");
containerSendToFriend.visible = false;
}
<fx:Declarations>
<s:HTTPService id="emailService" url="src/mail.php" method="POST"
resultFormat="xml" useProxy="false"
result="emailResultSTF()"
fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail + '\n' + event.message.toString())"/>
</fx:Declarations>
这是我的 PHP 代码:
$fileatt_type = "application/octet-stream";
$fileatt_name = "baignoireElyseeConcept.png";
$sender_name = $_POST['senderName'];
$email_from = $_POST['senderEmail'];
$email_subject = $_POST['emailSubject'];
$email_message = $_POST['emailMessage'];
$email_to = $_POST['emailFriendSTF'];
$headers = 'From:'.$sender_name.'<'.$email_from.'>';
$data= $_POST['file'];
$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=\"utf-8\"\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-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
$mailsend = mail($email_to, $email_subject, $email_message, $headers);
玛丽