My script works to perfectly now. You have to set the following variables in your form.
Make a form in a new movie clip with text boxes for
name
email
subject (optional- you can choose to incorporate an unvarying subject in the php file)
message
And Most importantly uploadfile
somewhere you have to set uploadfile = "" + selectedFile.name + "";
I have on the send button if everything else is ok
_root.emailform.uploadfile = "" + selectedFile.name + "";
Here is the latest version of the .php file to send mail
?php
$newfile = $_POST['uploadfile'];
$fileatt = "files/" . $newfile; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = $_POST['uploadfile'];; // Filename that will be used for the file as the
$from = $_POST['email'];
$email_from = $from; // Who the email is from
$email_subject = $_POST['subject']; // The Subject of the email
$email_txt = $_POST['message']; // Message that the email has in it
$email_to = "webmaster@flashattach.com"; // Who the email is too
$headers = "From: ".$email_from;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($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 .= $email_txt . "\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_txt . "\n\n";
$data = chunk_split(base64_encode($data));
$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";
$ok = @mail($email_to, $email_subject, $email_message, $headers);
?> I also have a way to delete the file from the server.
Make the movie play for a few frames after the send (reinforce the user that something has happened)
On the third or fourth (etc) frame put this code
_root.emailform.loadVariables("unlink.php", "POST");and in the same directory on your server as all the other files make a php file called unlink.php with this code
<?php
unlink("/completepathtoserver/files/".$_POST['uploadfile']);
?>when I say complete path to server I mean it. just putting your domain/files sometimes doesn't work
visit your control panel to find the absolute complete path to your server
Remember though, if someone loads a file and then just leaves, the file will remain on your server until you delete it or set up some kind of automation for deleting the files.
use jorges example to upload the file. you can also set the variable
_root.emailform.uploadfile = "" + selectedFile.name + "";
inside that code as well
just give your form movie clip the instance name emailform
I am commissioning a designer to make a more professional looking form for this.
See a rudimentary version in action at my new site
http://www.flashattach.comemail me for any more questions or comments