Welcome, Guest
  • Author Topic: sending an attachment in a flash email?  (Read 55237 times)

    Musicman

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 2685
      • View Profile
      • Email
    Re: sending an attachment in a flash email?
    « Reply #30 on: 03/24/06, 01:21 »
    Hi,

    a) your first $headers = statement adds a \n, then the next one adds an extra \n (before the MIME stuff). The two \n in a row actually start the mail body, so one set of headers ends up in the mail body
    b) I guess you did not intend to use different sender_mail and sender_email fields
    c) for deleting, why not add
    unlink($fileatt)
    near the end of your script

    Musicman

    roger jones

    • Server what's that
    • *
    • Posts: 32
    • http://flashattach.com.com
      • View Profile
      • Flash Addons In A Flash
      • Email
    Re: sending an attachment in a flash email?
    « Reply #31 on: 03/24/06, 10:05 »
    Thanks for the pointers. I had actually been thinking about why I don't have unlink in the same email script. But the problem I am facing now is how to delete a file that is loaded and the user abandons the site before sending. I have searched and searched for something that deletes an entire directory, but I am having no luck. If I found that I would be all set as I would simply delete the directory and recreate it every time. Another problem with that is if there are two users using the program at one time.
    Sick Webmaste Scripts http://www.sickscripts.com
    Flash Addons In A Flash http://www.flashattach.com
    That's Profound! http://www.thatsprofound.com
    Free Flash Email Forms at http://flashmailforms.com
    Webmaster Articles http://www.webhostingpapers.com

    roger jones

    • Server what's that
    • *
    • Posts: 32
    • http://flashattach.com.com
      • View Profile
      • Flash Addons In A Flash
      • Email
    Re: sending an attachment in a flash email?
    « Reply #32 on: 03/24/06, 10:08 »
    how should this look exactly after your modifications with the new lines?
    Code: [Select]
    $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"; 
    Thanks
    Sick Webmaste Scripts http://www.sickscripts.com
    Flash Addons In A Flash http://www.flashattach.com
    That's Profound! http://www.thatsprofound.com
    Free Flash Email Forms at http://flashmailforms.com
    Webmaster Articles http://www.webhostingpapers.com

    Musicman

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 2685
      • View Profile
      • Email
    Re: sending an attachment in a flash email?
    « Reply #33 on: 03/24/06, 12:27 »
    Code: [Select]
    $headers = "From: " . $_POST['sender_name'] . " <" . $_POST['sender_mail'] . ">\n";

    $headers .= "MIME-Version: 1.0\n" .
                "Content-Type: multipart/mixed;\n" .
                " boundary=\"{$mime_boundary}\""; 
    this is the two pieces that make up the headers. I removed the initial \n from the second one - you could as well keep that and get rid of the trailing \n in the first line of code

    About deleting: two possible approaches
    a) upload the image along with the data
    b) delete files based on age
    To handle the simultaneous access problem, just avoid renaming the image to whatever it was named on the visitor's desktop - keep the unique name created by php.
    A good (but somewhat hard to understand) solution would be to store the original name in a session (in case it means anything to the recipient of the mail) and to use a modified session handler that cleans unused images

    Musicman

    Musicman

    ap7_girl82

    • Server what's that
    • *
    • Posts: 5
      • View Profile
      • Email
    Re: sending an attachment in a flash email?
    « Reply #34 on: 04/06/06, 23:43 »
    Waaaaa....   :'(  :'( :'(

    I'm so frustrated. I been trying this for 2 week but still can't attach the file to my email. Can anybody check my working example?? I follow every single thing that been posted here but still can't manage to solve the problem. By the way musicman I think the PHP script I post here got mistake but I don't know where. Can somebody check my flash script??

    Quote
    //Allow this domain
    System.security.allowDomain("http://www.localhost.com/");
    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  {
       //clean statusArea and details area
       statusArea.text = " ";
       // 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.
       _root.emailform.uploadfile = ""+selectedFile.name+"";
       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;
    };
    // the file has uploaded
    listener.onComplete = function(selectedFile:FileReference):Void  {
       // Notify the user that Flash is starting to download the image.
       statusArea.text += "Upload finished.\nNow downloading "+selectedFile.name+" to player\n";
       //Show file details
    };
    var imageFile:FileReference = new FileReference();
    imageFile.addListener(listener);
    uploadBtn.onPress = uploadImage;
    // Call the uploadImage() function, opens a file browser dialog.
    function uploadImage(event:Object):Void {
       imageFile.browse([{description:"Image Files", extension:"*.jpg"}]);
    }

    stop();



    Please!! It will be a big favour if you can help me!!

    Waaaa.......... :-[ :'( :-\ ???

    nothingGrinder

    • Mods
    • Systems Administrator
    • *****
    • Posts: 823
    • Automatic websites with social media distribution
      • View Profile
      • nothingGrinder
    Re: sending an attachment in a flash email?
    « Reply #35 on: 04/07/06, 01:42 »
    if you need help attaching  a file, you should show the PHP script you are using, this is all Flash and it has nothing to do with attaching a file to an email, and if you think you have problems with your flash script, you should be more specific as to what the problem is.

    Musicman

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 2685
      • View Profile
      • Email
    Re: sending an attachment in a flash email?
    « Reply #36 on: 04/08/06, 13:01 »
    Hi,

    unfortunately I cannot help much here, because macromedia has not yet released flash player 8 for my system (and will, in fact, wait for fp 8.5)
    Usually I just try sending mail with a http tracer and watch what happens:
    - does it send anything?
    - does the data it sends make sense? (for an image upload, you need the specific multipart/form-data format)
    - does the server return any error messages (like syntax error in line 13 of the php file)
    - if not, does the server say it is happy
    Try to find a suitable tool (if nothing else, ethereal exists on almost every os) and do these checks.
    Then you will know whrther you need flash or php help

    Musicman

    ap7_girl82

    • Server what's that
    • *
    • Posts: 5
      • View Profile
      • Email
    Re: sending an attachment in a flash email?
    « Reply #37 on: 04/12/06, 21:22 »
    I'm sooooo Happy  ;D  ::)  ;)!! At last I manage to send the email with the attachment. I want to say Thanks to Roger Jones , Musicman and Jorge for you wonderful tutorial. I'm so happy because I been working on this thing for 6 month already. Thank to this forum and all the people that help me. Thanks a lot men. You all ROCK!!

    trippin

    • Server what's that
    • *
    • Posts: 6
      • View Profile
    Re: sending an attachment in a flash email?
    « Reply #38 on: 04/13/06, 08:18 »
    well that's wonderful news now could you provide both flash and Php scripts here and share with the rest of the community so that we can all stop banging heads into walls....

    thanks

    chuckylefrek

    • Server what's that
    • *
    • Posts: 1
      • View Profile
      • Email
    Re: sending an attachment in a flash email?
    « Reply #39 on: 08/30/06, 03:08 »
    I am also having problems with the attachment not working.

    I have got it working so it creates a text file on the server and also it sends the email but just can't get that file to be sent as an attachment.

    Below is what I have so far. I would be very grateful for any help to get this working.

    Actionscript:
    Code: [Select]

    var vSender = new LoadVars();
    var vReceiver = new LoadVars();

    trace ("exportDesignData");


    vSender.action = "write";
    vSender.filename = "order9.txt";

    vSender.order_data = "&text1_Font=" + text1_Font;


    vReceiver.onLoad = function(success) {

    trace ("onLoad function");

    if (success) {
    trace("text writen to the text file:\n" + this.message);
    content_txt.text = this.message;
    } else {
    trace("error");
    content_txt.text = "error";
    }
    };


    vSender.sendAndLoad("http://www.mediakitchen.co.uk/clients/davehann/mail.php", vReceiver, "POST");



    And here is my PHP code:

    Code: [Select]


    <html>
    <head>
    <title> Sending Email </title>
    </head>
    <body>
    <?php


    $filename 
    $_POST['filename']; 


    $order_data $_POST['order_data'];



    if (!
    $handle fopen($filename'w')) {

     echo "&message=Cannot open file&";
     exit;

    }


    if (
    fwrite($handle$order_data) === FALSE) {
    echo "&message=Cannot write to file&";
    exit;
    }



    fclose($handle);

    // Read POST request params into global vars
    $to      "paul@mediakitchen.co.uk";
    $from    "paul_steven@btinternet.com";
    $subject "Attachment example";
    $message "Please find attached my design for my t-shirt order";

    $newfile $_POST['filename'];
    $fileatt $handle// Path to the file                 
    $fileatt_type "application/octet-stream"// File Type 
    $fileatt_name $_POST['filename'];; // Filename that will be used for the file as the 

    $headers "From: $from";

    if (
    is_uploaded_file($fileatt)) {
      // Read the file to be attached ('rb' = read binary)
      $file fopen($fileatt,'rb');
      $data fread($file,filesize($fileatt));
      fclose($file);

      // Generate a boundary string
      $semi_rand md5(time());
      $mime_boundary "==Multipart_Boundary_x{$semi_rand}x";
      
      
    // Add the headers for a file attachment
      $headers .= "\nMIME-Version: 1.0\n" .
                  "Content-Type: multipart/mixed;\n" .
                  " boundary=\"{$mime_boundary}\"";

      // Add a multipart boundary above the plain message
      $message "This is a multi-part message in MIME format.\n\n" .
                 "--{$mime_boundary}\n" .
                 "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
                 "Content-Transfer-Encoding: 7bit\n\n" .
                 $message "\n\n";

      // Base64 encode the file data
      $data chunk_split(base64_encode($data));

      // Add file attachment to the message
      $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";
    }

    // Send the message
    $ok = @mail($to$subject$message$headers);
    if (
    $ok) {
      echo "<p>Mail sent! Yay PHP!</p>";
    } else {
      echo "<p>Mail could not be sent. Sorry!</p>";
    }
    ?>

    </body>
    </html>




    Morf666

    • Server what's that
    • *
    • Posts: 2
      • View Profile
      • Email
    Re: sending an attachment in a flash email?
    « Reply #40 on: 03/08/07, 07:11 »
    HELLO TEHRE :)

    I HAVE THE SAME PROBLEM LIKE ap7_girl82 WHO AT 03/16/06, 21:31 POSTED!!!
    ..so i realised that i should b some real problem - please because ap_girl82 HAVE FOUND SOLUTION - SHERE IT WITH US!!!

    --------------------------------------------------------------------------------

    I had been trying to send email with attachment using flash and PHP for couple of month already. I try to send a picture as attachment but in my inbox show there a picture as attachment but the size is only 1K and it’s an empty attachment and there no picture at all.

    just 2 add - i use roger jones script


    file upload.php

    <?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);
    ?>

    file emailattach.php

    <?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@yoursite.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);

    ?>


    and - i have created folder FILES in folder where i`ve posted all this (with flash file) and i`ve chmoded all files in2 777 or 755.

    AND STILL - AS I SAID - after testing it via browser theres no file in folder files, and on my mail i get whole mail with info and attachment named like file i`ve sent but it`s 1kb big and it`s not THE FILE...

    HOPE SOME1 CEN HELP ME:)
    Morf666

    Musicman

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 2685
      • View Profile
      • Email
    Re: sending an attachment in a flash email?
    « Reply #41 on: 03/08/07, 14:05 »
    Hi,

    if I understand that right, there are two separate steps:
    step 1 uploads an image via flash movie, and uses upload.php to store the file.
    When step 1 completes, there is no file, so you have a problem with step 1.
    I have not had a chance to test anything like that, but I would suggest
    a) to manually set permissions on files folder to 777 (and remove that line from the script)
    b) add some messages for debugging, e.g.
    upload an empty text file log.txt and give it 666 permissions
    in your upload script, add
    $fp = fopen("log.txt", "a");
    fputs($fp, "upload " . $_FILES['Filedata']['tmp_name'] . " with name " . $_FILES['Filedata']['name'] . "\n");
    fclose($fp);

    step 2, once step 1 works, needs to be given the name of the file to send. Does your movie ensure it is the same name, or can there be user error?
    It is certainly worth testing step 2 by itself ... upload some image file via ftp and see whether that can be sent to your inbox (it should :)

    Musicman

    Morf666

    • Server what's that
    • *
    • Posts: 2
      • View Profile
      • Email
    Re: sending an attachment in a flash email?
    « Reply #42 on: 03/17/07, 14:51 »
    Yo Musicman - thanx for your reply but STILL NO PROGRESS :(

    to make my problem more simple..

    I used your tutorial "Uploading files with Flash 8" (at http://flash-db.com/Tutorials/upload/ ) and first i`ve realized that my browser (IE 6.0) have problem with downloading picture which was uploaded to player - but I can upload it - what is the most important to me.

    now, I upload on my server Source Files (upload.php, upload.swf) and in that directory I make "files" folder (as it`s said in READ ME) and all the files and folder "files" have WRITTE PERMISSIONS (chmod 777)

    when i start flash from browser and try uploading - message from flash is like in tutorial demo - Attempting, Uploading, Uploaded and downloading 2 player and then player says Sorry, error downloading your file.. but in case of your tutorial demo - my file is not displayed (because of some problems with my browser) but it`s allways uploaded! in case of my test - NOTHING - NO FILES WERE UPLOADED!

    ..i`ve asked my host about uploading files and they said that all uploads are allowed and I tried with HTML uploader - and it worked without a problem..

    HOPE U CAN HELP ME SOMEHOW..
    as i read here, ap7_girl82 had the same problem like me..:(

    THNX
    Morf666

    apostrof

    • Server what's that
    • *
    • Posts: 1
      • View Profile
    Re: sending an attachment in a flash email?
    « Reply #43 on: 01/21/08, 09:49 »
    ap7_girl82 could you please post your sources(php & flash) ?

    we need your help:)

    thanks in advance!

    '

    djbdr248

    • Server what's that
    • *
    • Posts: 9
      • View Profile
      • Email
    Re: sending an attachment in a flash email?
    « Reply #44 on: 02/06/09, 13:20 »
    Yeah I give up on doing it that way.
    I'm just going to upload the file to my server and send them a link.

    I need to save a MC area as a jpg and just upload it to a server.
    any idea how I go about saveing an area to a jpg to upload it? (PHP)