Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8596723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:44:52+00:00 2026-06-12T00:44:52+00:00

First I try’d doing it with Mail_mime from Pear, but I can’t load the

  • 0

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.

Next I followed directions from this post
.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?

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..

Also if anybody has another solution or php class to send the image in the body of the mail
as opposed to an attachment

I send this with ajax

var canvas = document.getElementById('doodle');
function serialize(canvas) {
    return canvas.toDataURL();
}

this is serverside

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-> 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." <".$from_mail.">\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!";
    }
}   

thanks, Richard

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:44:53+00:00Added an answer on June 12, 2026 at 12:44 am

    You should first of all better make yourself comfortable with the problem you face. Is it either:

    1. Converting a canvas to an image “file”   -or-
    2. Attaching an image “file” to an outgoing mail message

    You would not be able to do 2. in your scenario without doing 1., however 2. can be solved independently of 1..

    I suggest you either ask the one or the other. To integrate both would be actually quite straight forward:

    • If you have a mail library that only accepts files for attachment, you would need to create a temporary file. You can create temporary files in PHP with the SplTempFileObject quite easily.
    • If you have a mail library that accepts a binary string for an attachment, you can just pass the binary string.
    • If you need to debug whether or not creating a file out of the canvas bitmap data did work, you should save to a file and the test if the file is an image (this is most easily done manually, however this can be automated, too)

    Sorry if this answer is more like a comment, it’s just that I do not find much use in actually providing code as the question is that much segmented.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My first try of MVC. Am trying to implement a simple example. Inspiration from
I try to create styles with first-child and last-child items but I encountered a
This is my first try trying to use WCF, so I'm guessing I'm doing
I'm trying to do a many-to-many relationship in rails. It's my first try but
I first try to append a template but got the same issue where it
It's my first try using the @if control directive from SASS . I have
I was trying to learn CoffeeScript, and made this simple class as first try:
I try to subtract two dates from each other but unfortunately without success. Maybe
the first try to call that->getValue() looks good, but just the line below (the
New to batch files, first try actually. Trying to make a simple batch file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.