【发布时间】:2016-11-01 13:04:47
【问题描述】:
我有在客户邮件中发送图像 div 的联系表单
<form name="form" method="post" action="mail.php" id="myForm">
</form>
表单通过输入类型提交提交
<input name="submit" type="submit" value="Submit" id="capture" />
我用于发送电子邮件的 php 是
<?php
include("auth.php");
//message
$message = $_POST['msg'];
$username =$_REQUEST['username'];
$surname =$_REQUEST['surname'];
$name= $_REQUEST['name'];
$filename = md5(uniqid(rand(), true));
$imageurl = 'http://panosmoustis.netai.net/barcodeimage/'.$filename.'.png';
//mail body - image position, background, font color, font size...
$body = "Dear $surname $name
Thank you for your Pre-registration for Global.
Please print the attached e-ticket with your personal barcode and bring it to the reception of the exhibition.
This barcode includes data about you which is required during registration. Having this barcode will considerably speed up the registration process
Organizing committee.\n".
$body = "Print e-ticket
$imageurl.\n".
//to send HTML mail, the Content-type header must be set:
$headers='MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html;charset=iso-8859-1' . "\r\n";
$headers .= 'From: <http://panosmoustis.netai.net/>' . "\r\n";
$to = $_POST['mail'];
$subject = "EXPRESS REGISTRATION (Global)";
//mail function
$email = mail($to, $subject, $body, $headers);
if(!$email) {
echo "Error sending email";
} else {
echo "Your email was sent successfully.";
}
?>
然后我有一个 ajax 函数用于在服务器上保存动态创建的图像
<script>
$("#capture").click(function() {
html2canvas([document.getElementById('printableArea')], {
onrendered: function (canvas) {
var imagedata = canvas.toDataURL('image/png');
var imgdata = imagedata.replace(/^data:image\/(png|jpg);base64,/, "");
//ajax call to save image inside folder
$.ajax({
url: 'save_image.php',
data: {
imgdata:imgdata
},
type: 'post',
success: function (response) {
console.log(response);
$('#image_id img').attr('src', response);
}
});
}
})
});
</script>
我的用于在服务器上保存图像的 php 文件
<?php
$imagedata = base64_decode($_POST['imgdata']);
$filename = md5(uniqid(rand(), true));
//path where you want to upload image
$file = '/home/a7784524/public_html/barcodeimage/'.$filename.'.png';
$imageurl = 'http://panosmoustis.netai.net/barcodeimage/'.$filename.'.png';
file_put_contents($file,$imagedata);
echo $imageurl;
我的问题是我想在表单提交时将 imageurl 发送到电子邮件客户端 谢谢
【问题讨论】:
标签: javascript php html ajax