1 Reply Latest reply on Feb 5, 2008 4:33 AM by jibysk

    file as attachment in email form

      hi all,

      It would be a great help for me if any one can help me, how to send a file( minimum of 300k ) as attachment through a email form created in flex....

      please help me ...

        • 1. Re:  file as attachment in email form
          jibysk Level 1
          hi all i have got a php code which sends attachments via mail..... Please help me how to send the file parameters to the php via http service send method.... i am placing the php and flex codes here please help Sad

          PHP code


          $to = 'somemail@mail.com';
          $from = $_POST[email];
          $name = $_POST["name"];
          $subject = $_POST["title"];
          $emailMessage = $_POST["message"];

          $message = "\nFrom: $name\nEmail Address: $frommail\nContact Number: $phone\n\n $emailMessage";
          $message = StripSlashes($message);

          $fileatt = $_FILES['fileatt']['tmp_name'];
          $fileatt_type = $_FILES['fileatt']['type'];
          $fileatt_name = $_FILES['fileatt']['name'];

          $headers = "From: $frommail";

          if (is_uploaded_file($fileatt)) {

          $file = fopen($fileatt,'rb');
          $data = fread($file,filesize($fileatt));

          $semi_rand = md5(time());
          $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

          $headers .= "MIME-Version: 1.0\n" .
          "Content-Type: multipart/mixed;\n" .
          " boundary=\"{$mime_boundary}\"";

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

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

          $message .= "--{$mime_boundary}\n" .
          "Content-Type: {$fileatt_type};\n" .
          " name=\"{$fileatt_name}\"\n" .

          "Content-Transfer-Encoding: base64\n\n" .
          $data . "\n\n" .
          }else echo "File error! ";

          mail($to, $subject, $message,$headers);


          Flex code...

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" viewSourceURL="srcview/index.html" creationComplete="init();">

          <mx:HTTPService id="httpService" url=" http://jibysubhash.x10hosting.com/jibysk/sendmail.php" method="POST">
          <mx:request >

          private var file:FileReference = new FileReference();
          private function init():void
          file.addEventListener(Event.SELECT, selectHandler);

          private function selectHandler(event:Event):void


          private function browse(event:MouseEvent):void
          var filefilter:FileFilter = new FileFilter("Resume Files", "*.zip;*.doc;*.pdf;*.txt;*.rar;*.docx");


          <mx:Panel id="panel1" width="691" height="665" layout="absolute" title="Apply for the job" >
          <mx:Form x="0" y="0">

          <mx:FormItem fontWeight="bold" color="#000000" id="nam" label="Name : ">
          <mx:TextInput width="354" height="20" id="txtname" />
          <mx:FormItem fontWeight="bold" color="#000000" id="mail" label="Email : ">
          <mx:TextInput width="354" height="20" id="txtemail" />
          <mx:FormItem fontWeight="bold" color="#000000" id="phone" label="Phone/mobile : ">
          <mx:TextInput width="354" height="20" id="txtphmo"/>
          <mx:FormItem fontWeight="bold" color="#000000" id="post" label="Post applied : ">
          <mx:TextInput width="477" height="20" enabled="false" editable="false" id="txtpost" text="test mail"/>
          <mx:FormItem fontWeight="bold" color="#000000" id="upload" label="Upload resume : ">
          <mx:Button label="Browse" id="bro" click="browse(event);"/>
          <mx:FormItem fontWeight="bold" color="#000000" id="cover" label="Cover Letter : ">
          <mx:TextArea width="507" height="350" id="txtcover"/>
          <mx:FormItem label=" " >
          <mx:Button label="Send" id="applynow" click="httpService.send();" />

          <mx:Label x="210" y="125" text=" " maxWidth="300" id="statuss"/>