我有一个问题,就是使用jquery将base64_image发送到我的表单并在该页面上回显它以供客户预览。由于该表格是客户填写他们的信息并仔细检查图像,一旦他们确认,他们填写的数据将发送到我的电子邮件地址。但是,图像无法在预览部分和电子邮件中显示。
对于base64_image,是客户使用jquery来创建他们的设计图片。请在下面找到您的参考代码。
的index.php
$('#send-button').click(function(){
fpd.createImage(true, true);
return false;
});
//the handler when the image is created
$('#fpd').bind('imageCreate', function(evt, canvas, base64Image) {
//send 64-bit encoded image url to php
$.post("php/form.php", { base64_image: base64Image }, function(data) {
//successful
if(data) {
//open product image a new window
console.log('Mail successfully sent!');
}
//failed
else {
console.log('Mail could not be sent');
}
} );
});
<a href="php/form.html" id="send-button" class="btn btn-info">send</a>
form.php的
<form name= "myForm" form action="send.php" method="post" onsubmit="return validateForm()">
<td align="right" valign="middle" class="text">Picture Preview:<img src="<?=$base64_str;?>"></img></td>
</form>
send.php
$base64_str = substr($_POST['base64_image'], strpos($_POST['base64_image'], ",")+1);
$to = 'xxx@gmail.com';//set here your receiving mail address
$subject = 'test'; //set here the mail subject
$bound_text = md5(date('r', time()));
$bound = "--".$bound_text."\r\n";
$bound_last = "--".$bound_text."--\r\n";
$headers = "From: xxx@yahoo.com.hk\r\n";//set here the sending mail address
$headers .= "MIME-Version: 1.0\r\n"
."Content-Type: multipart/mixed; boundary=\"$bound_text\"";
$message .= "If you can see this MIME than your client doesn't accept MIME types!\r\n"
.$bound;
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n"
."Your message goes here\r\n" //set here the mail text
.$bound;
$message .= "Content-Type: image/png; name=\"mail_product.png\"\r\n"
."Content-Transfer-Encoding: base64\r\n"
."Content-disposition: attachment; file=\"mail_product.png\"\r\n"
."\r\n"
.chunk_split($base64_str)
.$bound_last;
if(mail($to, $subject, $message, $headers))
{
echo json_encode(1);
} else {
echo json_encode(0);
}
?>
答案 0 :(得分:0)
问题是什么?发送电子邮件或显示预览,或两者兼而有?
jQuery脚本是否正确地将数据发送到php文件?你有没有调试过这个?
(数据)中的返回值是多少?你得到0,1还是别的什么?
您是否已设置自己的smtp邮件服务器或使用gmail的smtp服务器?