PHPMailer,AddStringAttachment和数据URI方案 [英] PHPMailer, AddStringAttachment and Data URI Scheme

查看:142
本文介绍了PHPMailer,AddStringAttachment和数据URI方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用toDataURL()($contact_image_data)将canvas元素的内容转换为数据(URI方案),我想通过电子邮件将其作为附件发送.当前,这是我设置PHPMailer的方式:

I have converted the contents of a canvas element to data (URI Scheme) using toDataURL() ($contact_image_data) and I want to send this via email as an attachment. This is currently how I have PHPMailer set up:

$contact_image_data="data:image/png;base64,iVBORw0KGgo[...]";
$filename="test.png"; 
$encoding = "base64"; 
$type = "image/png";
$mail->AddStringAttachment($contact_image_data, $filename, $encoding, $type);   

我想知道这是否真的可能,如果可以的话,我错过了哪些步骤.

I am wondering if this is actually possible, and if so, what steps I am missing.

我可以发送电子邮件,附加一个名为"test.png"的文件,其中包含$contact_image_data的内容,但实际上并没有创建图像.

I can send an email, attach a file named "test.png" which contains the contents of $contact_image_data, but it doesn’t actually create an image.

任何帮助将不胜感激.

塞缪尔.

推荐答案

是的,应该可行.您要使用"image/png" MIME类型调用toDataURL()以便它知道如何输出吗?

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

尝试将脚本分为两个部分-确保您确实有PNG,然后尝试邮寄该邮件.

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

例如,编写时会在计算机上打开test.png吗?.

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);
?>

希望能有所帮助!

这篇关于PHPMailer,AddStringAttachment和数据URI方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆