Sending files by post, error

128 views
Skip to first unread message

Петя Иванов

unread,
Feb 27, 2018, 11:18:47 PM2/27/18
to MIT App Inventor Forum

I dont know php or any programming, but i need a some app sending an email with 4 images.
I try some methods of send files but all of them not worked for me.
I find a way to send those files, but when i send 1 or 2 files it works, but when i try send 4 files i have an error "java.lang.OutOfMemoryError"
Send images in base64 code with exstention "simplebase641" and i think those function eat all memory



on server side i find a mail php script and litle edit it to work for me
<?php
header('Content-type: text/html');
header('Access-Control-Allow-Origin: *');
if (isset ($_POST['phone'])) {
  $to = "yo...@mail.com"; // enter your mail
  $from = "fr...@site.com";
  $subject = "Email from android app";
  $subject = "=?utf-8?b?".base64_encode($subject)."?=";
if (($_POST['haveCar']) == 1) { $car = "from app"; } else {$car = "No";}
 $message = "site/app: "  . $car . "\nPhone: " .$_POST['phone']. "\nCity: " .$_POST['city']."\n";
  $boundary = md5(date('r', time()));
 // $filesize = '';
  $headers = "MIME-Version: 1.0 \r\n";
  $headers .= "From: " . $from . "\r\n";
  $headers .= "Reply-To: " . $from . "\r\n";
  $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n";
$filename3 = $_POST['fileFF3filename'];
$filetype = "image/jpg";
$filesize = "5000000";
$attachment3 = chunk_split($_POST['fileFF3']) ;
$filename4 = $_POST['fileFF4filename'];
$attachment4 = chunk_split($_POST['fileFF4']) ;
  $message="
Content-Type: multipart/mixed; boundary=\"$boundary\"

--$boundary
Content-Type: text/plain; charset=\"utf-8\"
Content-Transfer-Encoding: 7bit

$message";

//  for($i=0;$i<count($_FILES['fileFF']['name']);$i++) {
//     if(is_uploaded_file($_FILES['fileFF']['tmp_name'][$i])) {
//      $attachment = chunk_split(base64_encode(file_get_contents($_FILES['fileFF']['tmp_name'][$i])));
//        $filename = $_FILES['fileFF']['name'][$i];
//       $filetype = $_FILES['fileFF']['type'][$i];
//        $filesize += $_FILES['fileFF']['size'][$i];
       $message.="

--$boundary
Content-Type: \"$filetype\"; name=\"$filename4\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=\"$filename4\"

$attachment4";
       $message.="

--$boundary
Content-Type: \"$filetype\"; name=\"$filename3\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=\"$filename3\"

$attachment3";
//     }
 //  }
   $message.="
--$boundary--";

  if ($filesize < 20000000) { // test file size
    mail($to, $subject, $message, $headers);
    echo $_POST['phone'].', Message sended!';
  } else {
    echo 'Size >2.';
  }
}
?>


Петя Иванов

unread,
Feb 28, 2018, 6:13:37 AM2/28/18
to MIT App Inventor Forum
it works whithout any actions O_o

another question
i need that the app while installing create an icon at the phone desktop automatically

and dont working, close the app while backpressed do close application 

Horst Schulze

unread,
Mar 1, 2018, 8:25:51 AM3/1/18
to MIT App Inventor Forum
it seems that your problem is that it is to large. Can you send it file after file? You can send the next file, when the web-event respond that the first has arrived.
Reply all
Reply to author
Forward
0 new messages