Hello what im trying to do is very simple however I guess its just not simple enough for me
Anyway my problem is I can quite make the attachment part of my flash/PHP emailer work.
All I want to do is attach one file to an email, Basically a persons resume.
I have the email part working I just cant seem to get the attachment to attach and send. The file is going to already be on the server, I used a tutorial to get files uploaded.
this is my email actionscript:
Code:System.useCodepage = true; send_btn.onRelease = function() { my_vars = new LoadVars(); my_vars.sendername = name_box.text; my_vars.sender = email_box.text; my_vars.message = message_box.text; if (my_vars.sender != "" and my_vars.sendername != "" and my_vars.message != "") { my_vars.sendAndLoad("mailer.php", my_vars, "POST"); gotoAndStop(2); } else { error_clip.gotoAndPlay(2); } my_vars.onLoad = function() { gotoAndStop(3); }; }; email_box.onSetFocus = subject_box.onSetFocus=message_box.onSetFocus=function () { if (error_clip._currentframe != 1) { error_clip.gotoAndPlay(6); } };
this is my file upload actionscript:
here is my upload php:Code://imagePane change to text output //Allow this domain System.security.allowDomain("http://localhost/"); import flash.net.FileReference; // The listener object listens for FileReference events. var listener:Object = new Object(); // When the user selects a file, the onSelect() method is called, and // passed a reference to the FileReference object. listener.onSelect = function(selectedFile:FileReference):Void { // Flash is attempting to upload the image. statusArea.text += "Attempting to upload " + selectedFile.name + "\n"; // Upload the file to the PHP script on the server. selectedFile.upload("upload.php"); }; // the file is starting to upload. listener.onOpen = function(selectedFile:FileReference):Void { statusArea.text += "Uploading " + selectedFile.name + "\n"; }; //Possible file upload errors listener.onHTTPError = function(file:FileReference, httpError:Number):Void { imagePane.contentPath = "error"; imagePane.content.errorMSG.text = "HTTPError number: "+httpError +"\nFile: "+ file.name; } listener.onIOError = function(file:FileReference):Void { imagePane.contentPath = "error"; imagePane.content.errorMSG.text = "IOError: "+ file.name; } listener.onSecurityError = function(file:FileReference, errorString:String):Void { imagePane.contentPath = "error"; imagePane.content.errorMSG.text = "SecurityError: "+SecurityError+"\nFile: "+ file.name; } var imageFile:FileReference = new FileReference(); imageFile.addListener(listener); uploadBtn.onPress = uploadImage; imagePane.addEventListener("complete", imageDownloaded); // Call the uploadImage() function, opens a file browser dialog. function uploadImage(event:Object):Void { imageFile.browse([{description: "Text Files", extension: "*.txt;*.rtf;*.doc"}]); } // If the filedoes not download, the event object's total property // will equal -1. In that case, display am error message function imageDownloaded(event:Object):Void { if(event.total == -1) { imagePane.contentPath = "error"; } } function downloadImage(file:Object):Void { imagePane.contentPath = "./files/" + file; }
and here is my email php:PHP Code:<?php
//create the directory if doesn't exists (should have write permissons)
if(!is_dir("./files")) mkdir("./files", 0755);
//move the uploaded file
move_uploaded_file($_FILES['Filedata']['tmp_name'], "./files/".$_FILES['Filedata']['name']);
chmod("./files/".$_FILES['Filedata']['name'], 0777);
?>
The upload script puts the file in a folder called files. How do I put the file into the email?PHP Code:<?php
// read the variables from the strings
$sendername = $_REQUEST["sendername"];
$subject = "Resume from website.";
$message = $_REQUEST["message"];
$sender = $_REQUEST["sender"];
// include sender IP in the message and the senders name.
$full_message = "Sender IP: " . $_SERVER['REMOTE_ADDR'] . "\n\n" . "From: " . $sendername . "\n\n" . $message;
$message= $full_message;
// remove the backslashes that normally appears when entering " or '
$message = stripslashes($message);
$sender = stripslashes($sender);
// send the email
if(isset($message) and isset($subject) and isset($sender)and isset($sendername)){
mail("[email protected]", $subject, $message, "From: $sender");
}
?>
At this point the only thing left is getting the file to attach to the email and send it, however I cant figure this out. If anyone could help me I would really appreciate it.
Thanks
PS: I have attached my files
PSS: I couldnt attach the fla since its too big so I have attached the swf




Reply With Quote