Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to send HTML5 canvas image with email
    primarykey
    data
    text
    <p>First I try'd doing it with Mail_mime from Pear, but I can't load the class from my shared host provider and cpanel.</p> <p>Next I followed directions from <a href="https://stackoverflow.com/questions/6150880/email-an-image-created-on-html5-canvas">this post</a> .It writes the image to the "temp" folder but it writes zero bytes. Obviously the question is, what am I missing. Somewhere I read about converting + signs in the encoded string, but i'm not sure?</p> <p><strong>The main problem is how to send the canvas image with email, I don't have a complete knowledge for going about that. I followed some posts and I thought I needed to create a temporary image file on the serverside to be able to attach it to an email with the build in mail function. Because 0 bytes where actually written, it seemed logical to solve that problem first and the mail problem would solve itself. From the comments below, it seems creating an image first is not neccesary, but I have to investigate some more before I have a workable solution..</strong></p> <p>Also if anybody has another solution or php class to send the image in the body of the mail as opposed to an attachment</p> <p>I send this with ajax</p> <pre><code>var canvas = document.getElementById('doodle'); function serialize(canvas) { return canvas.toDataURL(); } </code></pre> <p>this is serverside</p> <pre><code>case 'doodle': $image = $_POST['doodle']; $data ="doedeliedoe"; $email ="from@msn.com"; $headers="From:".$email."\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; list($settings, $encoded_string) = explode(',', $image); list($img_type, $encoding_method) = explode(';', substr($settings, 5)); if($encoding_method == 'base64'){ $file=fopen("/home/user/public_html/user/temp/newLego.png",'w+'); fwrite($file,base64_decode($encoded_string)) ; fclose($file); } $my_file = "newLego.png"; $my_path = "/home/user/public_html/user/temp/"; $my_subject = "My Design"; $my_message = "Designed by ".$email; $this-&gt; mail_attachment($my_file, $my_path, "mymail@gmail.com", $email, $email, $email, $my_subject, $my_message); function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) { $file = $path.$filename; $file_size = filesize($file); $handle = fopen($file, "r"); $content = fread($handle, $file_size); fclose($handle); $content = chunk_split(base64_encode($content)); $uid = md5(uniqid(time())); $name = basename($file); $header = "From: ".$from_name." &lt;".$from_mail."&gt;\r\n"; $header .= "Reply-To: ".$replyto."\r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; $header .= "This is a multi-part message in MIME format.\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $header .= $message."\r\n\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here $header .= "Content-Transfer-Encoding: base64\r\n"; $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; $header .= $content."\r\n\r\n"; $header .= "--".$uid."--"; if (mail($mailto, $subject, "", $header)) { //echo "mail send ... OK"; // or use booleans here } else { // echo "mail send ... ERROR!"; } } </code></pre> <p>thanks, Richard</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload