【发布时间】:2016-07-23 23:50:11
【问题描述】:
我正在尝试将画布图像发送到电子邮件。
首先,我使用 html2canvas.js 将 div 内容捕获到画布然后我得到 dataurl 现在我想将该图像上传到电子邮件。
请帮我解决问题
<div class="container">
<p>Some content goes here this content may have stylish text and icons</p>
<p>More contents</p>
</div>
<input type="submit" id="capture_div">
<script>
$(function(){
$('#capture_div').click(function(){
html2canvas($('.container'), {
onrendered: function (canvas) {
var img = canvas.toDataURL("image/png");
$.ajax({
type: "post",
url: "send_mail.php",
data: {img: canvas.toDataURL("image/png")},
dataType: "json",
success: function (data) {
..................
},
error: function () {
.................
}
});
}
}
</script>
我现在得到了 send_mail.php 中的值
<?php
$msg = '<img width="160" height="160" alt="star" src="'.$_POST['img'].'" />';
mail("someone@example.com","My subject",$msg);
?>
【问题讨论】:
-
...想将该图像上传到电子邮件吗?不明白要上传谁的电子邮件以及何时上传?但是您可以通过 ajax 将 dataurl 发送到后端。只需附加到表单
-
感谢您的回复我不想将dataurl发送到电子邮件,我需要在单击提交按钮后插入动态生成的画布图像作为消息。
-
你可以像这样添加图片
'<img width="160" height="160" alt="star" src="data:image/gif;base64,R0lGODlhEA....." /> -
没有成功的空邮件。
-
分享代码以更好地理解。
标签: jquery ajax html5-canvas