0

我在使用 jquery 将 base64_image 发送到我的表单并在该页面上回显以供客户预览时遇到问题。由于该表格是让客户填写他们的信息并仔细检查图像,一旦他们确认,他们填写的数据将发送到我的电子邮件地址。但是,图像无法在预览部分和电子邮件中显示。

对于 base64_image,是客户使用 jquery 来创建他们的设计图片。请在下面找到您的参考代码。

索引.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>

表单.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>

发送.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);
}  

?>
4

1 回答 1

0

有什么问题?发送电子邮件或显示预览,或两者兼而有之?

jQuery 脚本是否正确地将数据发送到 php 文件?你调试过这个吗?

(数据)中的返回值是多少?你得到0、1还是别的什么?

您是否设置了自己的 smtp 邮件服务器或使用 gmail 的 smtp 服务器?

于 2013-09-05T08:03:22.887 回答