1

I'm trying to send an email with an image taken with the camera from a smartphone. So far, it's going great. I'm sending a post request to my hosted php script from the device, with a Base64 string as post data which represents the picture taken by the user. Although, when I try to mail the image, it doesn't really seem to work out because I get the plain string instead of the image. What's the best technique to solve this and get the image in my mail instead of 2mb ofplain text? ;)

This is my php script:

$to = "secret@gmail.com";
$subject = "New bug report request!";

$pic1 = $_POST["pic1"];
$headers = "From: info@blablabla.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "
                <html>
                <head>
                <title>New bug report request!</title>
                </head>
                <body>
                <h1>New bug report request!</h1>
                <hr>
                <p>Name: asdfdasf<br>
                Email: asdfasdf>
                Website URL:asdfasdf<br>
                Description: asdfasdf<br>

                <img src=\"data:image/png;base64,$pic1\"/>

                </p>
                </body>
                </html>
                ";
mail($to,$subject,$message,$headers);

At the moment I'm getting something like this:

Maybe I'm using wrong techniques to solve this, any help is welcome :-)

Community
  • 1
  • 1
Markinson
  • 2,077
  • 4
  • 28
  • 56

1 Answers1

1

For people wanting to know how I fixed it:

I sent the Base64 image with an AsyncTask to my PHP script which decodes the string into an image, which is then stored on the server with as name a timestamp. After that, I get the right images and add them to a mail as an attachment using PHPMailer. Then I send the email and I get the pictures in a mail as attachment. Hope it can help some people!

Markinson
  • 2,077
  • 4
  • 28
  • 56