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

    Conextar

    • Server what's that
    • *
    • Posts: 3
      • View Profile
      • Email
    Re: sending an attachment in a flash email?
    « Reply #15 on: 02/06/06, 11:42 »
     ;D ;D ;D ;D

    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 #16 on: 03/07/06, 06:49 »
    I have got a working version of flash sending attachment with email using php here

    http://flashattach.com
    « Last Edit: 04/09/06, 06:03 by roger jones »
    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

    trippin

    • Server what's that
    • *
    • Posts: 6
      • View Profile
    Re: sending an attachment in a flash email?
    « Reply #17 on: 03/13/06, 23:10 »
    THat's great but can we actually get to see the code ? Please !!!
    I tried playing with what you posted and adapting it but never ever managed to get it working ...

    please post the fla code + php so that we can see how it integrates ,
    it would help so much ... mine just wont attach ...

    thank you

    ap7_girl82

    • Server what's that
    • *
    • Posts: 5
      • View Profile
      • Email
    Re: sending an attachment in a flash email?
    « Reply #18 on: 03/16/06, 21:31 »
    Hai! I'm facing a same problem also. 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. I have a question here, how to send variables (path to the file) from flash to PHP? Currently this is how I send the variable from flash

    Quote
    on (release) {
       sender_to = _root.Sto.text;
       sender_mail = _root.Semail.text;
       sender_name = _root.Sname.text;
       sender_subject = _root.Ssubject.text;
       sender_message = _root.Smessage.text;
       sender_attach = _root.attachMovie("c:\\postcard.jpg");
       loadVariables("http://www.malaysiaiguide.com/sendmail.php", this, "POST");
       this.onData = function() {
          for (var a in this) {
             trace([a, this[a]]);
          }
          _root.nextFrame();
          if (this.output == 'sent') {
             _root.errTitle = 'Thank You.';
             _root.errType = "Your message has been successfully sent.";
          } else {
             _root.errTitle = "Error!";
             _root.errType = "Attention, an error occurred while processing your message. Please try again later.";
          }
       };
    }

    As for PHP script, I’m using the same script as posted by “roger jones”. I have the working example just let me know if u want me to post it here. Please check my script and let me know what I done wrong.

    Musicman

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

    if you know a specific file is on the server, you should use the path on the server, e.g.
    sender_attach = 'images/postcard.jpg';
    If the file is on your desktop, you need to transfer it to the server first

    Musicman

    trippin

    • Server what's that
    • *
    • Posts: 6
      • View Profile
    Re: sending an attachment in a flash email?
    « Reply #20 on: 03/17/06, 18:31 »
    Let's say roger jones  PHP script works as is ....

    what would the script in flash  look like ?????

    I can't connect the 2 ... it works for all fields just not for browse .. it never passes the
    path & filename .... anyone ???

    cheers

    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 #21 on: 03/17/06, 23:11 »
    Post in one thread, reply bounces to another thread. Spooky
    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

    trippin

    • Server what's that
    • *
    • Posts: 6
      • View Profile
    Re: sending an attachment in a flash email?
    « Reply #22 on: 03/18/06, 06:05 »
    roger can you please help us ? you had the flash side working ...

    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 #23 on: 03/19/06, 00:45 »
    Yes, I have it working completely solid. http://www.flashattach.com to get your copy.
    « Last Edit: 06/26/06, 17:54 by roger jones »
    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

    ap7_girl82

    • Server what's that
    • *
    • Posts: 5
      • View Profile
      • Email
    Re: sending an attachment in a flash email?
    « Reply #24 on: 03/19/06, 22:37 »
    same to me also it works for others field except the attachment file, I just don't know how to send the file to the server. Can it be achive with flash??

    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 #25 on: 03/20/06, 09:00 »
    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

    Code: [Select]
    ?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
    Code: [Select]
    _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
    Code: [Select]
    <?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.com

    email me for any more questions or comments
    « Last Edit: 03/20/06, 11:49 by roger jones »
    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

    trippin

    • Server what's that
    • *
    • Posts: 6
      • View Profile
    Re: sending an attachment in a flash email?
    « Reply #26 on: 03/20/06, 21:40 »
    Yes but we need tha flash code to understand this

    _root.emailform.uploadfile = "" + selectedFile.name + "";

    what is uploadfile ?

    what is selectedFile ?

    what is .name ???

    What fields these variables belong to ? You need to explain more the flash side of it.
    I emailed you , you never replied ... We keep going in circles
    just put the flash code on here so that we can see what needs to be
    passed and how to php

    Thanks
    « Last Edit: 03/20/06, 22:29 by trippin »

    Musicman

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 2685
      • View Profile
      • Email
    Re: sending an attachment in a flash email?
    « Reply #27 on: 03/23/06, 02:38 »
    Hi,

    sorry I cannot comment on the flash side of things but the php seems to be wrong - or misleading...
    If the script receives a filename through $_POST['uploadfile'] it definitely does not receive file data, just the name. This is great if you choose from files already on the server (but you probably would not want to erase them right after use in that case)
    In order to really receive an upload, consider this frogment
    Code: [Select]
    if(is_uploaded_file($_FILES['upload']['tmp_name']))
    {    $wantname = basename($_FILES['upload']['name']);   // this gets the user's supplied filename and strips off path components
         move_uploaded_file($_FILES['upload']['tmp_name'], "uploaddir/$wantname");
    }
    On some servers move_uploaded_file is the only way to make the data accessible, some others allow copy() as well

    Comment on that unlink.php file: suppose some idiot sends the string ../mail.php via a html form of their own to said unlink.php, and further assume that, for whatever reasons, the parent directory has full access rights (chmod 777 on unix) - your mail.php will be gone. Never accept ANY data from the web without checking

    Musicman

    trippin

    • Server what's that
    • *
    • Posts: 6
      • View Profile
    Re: sending an attachment in a flash email?
    « Reply #28 on: 03/23/06, 08:06 »
    great we still haven't resolved anything....  :-\

    ap7_girl82

    • Server what's that
    • *
    • Posts: 5
      • View Profile
      • Email
    Re: sending an attachment in a flash email?
    « Reply #29 on: 03/23/06, 23:19 »
    Hai musicman! Thank for that tips!

     I already try it, I manage to upload the image to the server and all the image I put under one folder and I name it as "files". This folder I put inside another folder call "upload". So the php and flash file I put inside upload folder together with the files folder. The main problem right now I still can't attach the image to my email. This is my php script and can you check my php script and let me know what's wrong with it.

    Quote
    <?php 
    if(is_uploaded_file($_FILES['upload']['tmp_name']))
    {    $wantname = basename($_FILES['upload']['name']);   // this gets the user's supplied filename and strips off path components
         move_uploaded_file($_FILES['upload']['tmp_name'], "files/$wantname");
    }
    $fileatt = "files/$wantname"; // Path to the file                 
    $fileatt_type = "image/jpg"; // File Type   

    $email_from = stripslashes($_POST['sender_email']); // Who the email is from 
    $email_subject = stripslashes($_POST['sender_subject']); // The Subject of the email 
    $email_txt = stripslashes($_POST['sender_message']);// Message that the email has in it 

    $email_to = "domain@domain.com"; // Who the email is too 

    $headers = "From: " . $_POST['sender_name'] . " <" . $_POST['sender_mail'] . ">\n";

    $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 .= "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_txt . "\n\n"; 

    $data = chunk_split(base64_encode($data)); 

    $email_message .= "--{$mime_boundary}\n" . 
                      "Content-Type: {$fileatt_type};\n" . 
                      " name=\"{$fileatt}\"\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); 

    if($ok) { 
    echo "<font face=verdana size=2>The file was successfully sent!</font>"; 
    } else { 
    die("Sorry but the email could not be sent. Please go back and try again!"); 

    ?>

    There another thing, I don't know how to delete image from the server after attach it to the email. I try the unlink.php script given by roger but nothing happen. Can you suggest another solution to delete file from the server.