php - Can't send an image ( on the fly) attachment with mail() -
i trying send attachment receive blank file. doing wrong?
so $_post["screenshot"]
it's image in da:image/png;base64,....
format , here seems ok, arrives without problem, happens than? why ireceive blank file? how send without saving before(commented area)?
<?php header("content-type: application/json; charset=utf-8"); if(isset($_post["screenshot"]) && strlen($_post["screenshot"]) > 0){ $data = str_replace("data:image/png;base64,", "", $_post["screenshot"]); // $png = fopen("screenshot.png", "w"); // fwrite($png, base64_decode($data)); // fclose($png); */ /* ___________ e-mail _____________ */ $to = 'mymail@mail.com'; $subject = 'test email'; $attachment = chunk_split($data); // random hash necessary send mixed content $separator = md5(time()); // carriage return type (we use php end of line constant) $eol = php_eol; // main header (multipart mandatory) $headers = "from: domain@mail.com\r\nreply-to: mymail@mail.com" . $eol; $headers .= "mime-version: 1.0" . $eol; $headers .= "content-type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol; $headers .= "content-transfer-encoding: 7bit" . $eol; $headers .= "this mime encoded message." . $eol; // attachment $headers .= "--" . $separator . $eol; $headers .= "content-type: application/octet-stream; name=\"" . "cartolina.png" . "\"" . $eol; $headers .= "content-transfer-encoding: base64" . $eol; $headers .= "content-disposition: attachment" . $eol; $headers .= $content . $eol; $headers .= "--" . $separator . "--"; //send mail mail($to, $subject, "", $headers); echo json_encode(array("ok"=>"evertyhing ok. ")); } else { echo json_encode(array("error"=>"not ok")); } ?>
Comments
Post a Comment