PHPMailer, AddStringAttachment and Data URI Scheme

后端 未结 2 1756
走了就别回头了
走了就别回头了 2020-12-10 16:02

I have converted the contents of a canvas element to data (URI Scheme) using toDataURL() ($contact_image_data) and I want to send this

相关标签:
2条回答
  • 2020-12-10 16:18

    Yes it should be possible. Are you calling toDataURL() with the 'image/png' MIME type so it knows how to output it?

    Try breaking your script into two components - make sure you really have a PNG then try mailing it.

    For example, will test.png open on your computer when written?..

    <?php
    $contact_image_data="data:image/png;base64,iVBORw0KGgo[...]";
    $fp = fopen('test.png', 'w');
    fwrite($fp, $contact_image_data);
    fclose($fp);
    ?>
    

    Hope that helps a bit!

    0 讨论(0)
  • 2020-12-10 16:27

    It turns out I needed to strip the data:image/png;base64, section and base64_decode() the data:

    $contact_image_data="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA";
    $data = substr($contact_image_data, strpos($contact_image_data, ","));
    $filename="test.png"; 
    $encoding = "base64"; 
    $type = "image/png";
    $mail->AddStringAttachment(base64_decode($data), $filename, $encoding, $type);          
    
    0 讨论(0)
提交回复
热议问题