【问题标题】:Send image url with form submit使用表单提交发送图像 url
【发布时间】: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


    【解决方案1】:
    $imageurl  = 'http://panosmoustis.netai.net/barcodeimage/'.$filename.'.png'
    

    这里你使用了字符串连接。

    但在这里你没有:

    $body = "Print e-ticket   $imageurl.\n".
    

    您只需要执行与创建具有随机文件名的 $imageurl 时相同的操作即可:)

    【讨论】:

    • 我已经测试过了,因为图片包含客户信息,所以给出了错误的图片 url
    • 你能发布错误,并告诉我们它什么时候给你错误?
    猜你喜欢
    • 1970-01-01
    • 2021-01-27
    • 2011-07-22
    • 2020-10-18
    • 2017-03-07
    • 1970-01-01
    • 2015-02-20
    • 2012-01-24
    • 1970-01-01
    相关资源
    最近更新 更多