1

我正在尝试在我的自定义 php 表单中实现 uploadcare 小部件,它将获取用户上传的所有图像,并向图像添加图像 URL 和文件名等附加信息,并通过电子邮件将这些附加数据发送给客户端。我已经成功实现了表单和电子邮件模板。问题是,当我发送表单时,生成的电子邮件仅包含一张图像的信息。

如果我听起来有点含糊,请查看代码,其中所有由 uploadcare 小部件上传的图像都作为列表项插入到列表中。

 $ = uploadcare.jQuery;
     function installWidgetPreviewMultiple(widget, list) {
       widget.onChange(function(fileGroup) {
         list.empty();
         if (fileGroup) {
           $.when.apply(null, fileGroup.files()).done(function() {

             $.each(arguments, function(i, fileInfo) {
               // display file preview
               var $filename = fileInfo.name;
               var $fileurl = fileInfo.cdnUrl;
               var $src = fileInfo.cdnUrl + '-/resize/100x100/filename.jpg';
               var $sendurl = $("<input>").attr("type","hidden").attr("name","fileurl").val($fileurl);
               var $itemnu = 0;
               list.append(
            $('<li class="thumb_list_item"><input type="hidden" name="items" id="items" value="' + $fileurl +'"><img src="' + $src+ '" alt="Image Preview">' + '<h4 class="filename">' + $filename + '</h4>' + '<div class="get-layer-wraper"><ul class="get-layer"><li class="layer-name"><label for="white-layer" class="layer-title">White Layer : </label></li><li><input id="white-layer" name="white-layer" class="layer" type="number" value="0"/></li><li>PX</li></ul><div class="clear"><ul class="get-layer"><li class="layer-name"><label for="adhesive-layer" class="layer-title">Adhesive Layer : </label></li><li><input id="adhesive-layer" name="adhesive-layer" class="layer" type="number" value="0"/></li><li>PX</li></ul><div class="clear"><ul class="get-layer"><li class="layer-name"><label for="block-layer" class="layer-title">Blocking Layer : </label></li><li><input id="block-layer" name="block-layer" class="layer" type="number" value="0"/></li><li>PX</li></ul><div class="clear"><ul class="get-layer"><li class="layer-name"><label for="clear-layer" class="layer-title">Clear Layer : </label></li><li><input id="clear-layer" name="clear-layer" class="layer" type="number" value="0"/></li><li>PX</li></ul></div></li>').appendTo(".thumb_list")
            );

               list.append(
            $('<div>', {'class': 'layers'}).append($sendurl)                 
          );



             });
           });
         }
       });
     }

这是我用来发送电子邮件的mailer.php:

require 'vendor/autoload.php';
$sendgrid = new SendGrid('send_grid_api');
$mail = new SendGrid\Email();

 $name = "X";
 $email = "test@email.com";
 $fileurl = $_POST['fileurl'];
 $wlayer = $_POST['white-layer'];
 $alayer = $_POST['adhesive-layer'];
 $blayer = $_POST['block-layer'];
 $clayer = $_POST['clear-layer'];

 $msg = "White Layer: $wlayer, Adhesive Layer: $alayer, 
 Blocking Layer:      $blayer, Clear Layer: $clayer. 
 Download Link: $fileurl \n";

 $recipient ="test@email.com";
 $subject = "New Email";

$mail->
addTo( $recipient )->
setFromName($name)->
setFrom( $email )->
setSubject($subject)->
setText($msg);

//Send Mail.
if ($sendgrid->send($mail)) {
    header('Location: /thank-you/');
}
else{
    echo "failed";
}

我有中级 jquery 知识,但总是有点慢。所以请任何人帮助我。我只需要在电子邮件中包含所有图像 URL 和其他信息,而不仅仅是一个。

提前致谢。

4

1 回答 1

1

邮件部分 - 您可以在此处找到有关在 php 中使用 uploadcare 组的文档。一旦你通过它,你会看到你的正确的 mailer.php 将 URL 列表附加到邮件正文中,如下所示:

<html>
<head>
<?php
require_once 'vendor/autoload.php';
use \Uploadcare;

//make sure you replace your key values here
$sendgrid = new SendGrid('send_grid_api');
$api = new Uploadcare\Api('YOUR_PUBLIC_KEY', 'YOUR_SECRET_KEY');

$mail = new SendGrid\Email();
$name = "X";
$email = "test@email.com";


$group_id = $_POST['fileurl'];
$wlayer = $_POST['white-layer'];
$alayer = $_POST['adhesive-layer'];
$blayer = $_POST['block-layer'];
$clayer = $_POST['clear-layer'];
$group = $api->getGroup($group_id);
$group->store();
$files = $group->getFiles();
$msg = "White Layer: $wlayer, Adhesive Layer: $alayer, 
Blocking Layer:      $blayer, Clear Layer: $clayer \n";


for($i = 0; $i < count($files); $i++) {

    $msg.=$files[$i]->getUrl().' \n';

    }

 $recipient ="test@email.com";
 $subject = "New Email";

$mail->
addTo( $recipient )->
setFromName($name)->
setFrom( $email )->
setSubject($subject)->
setText($msg);

//Send Mail.
if ($sendgrid->send($mail)) {
    header('Location: /thank-you/');
}
else{
    echo "failed";
}

?>
</head>

<body>
</body>

</html>

对于第一部分 - 我在这里回答了类似的问题 - 唯一的区别是小部件初始化:

<?php echo $api->widget->getInputTag('fileurl',array('data-multiple' => true)); ?>`   

代替

 <?php echo $api->widget->getInputTag('fileurl'); ?>  

当然,您在表单中发送的字段名称应该与您在 POST 语句中的 mailer.php 中获得的字段名称相匹配。

于 2016-10-06T21:51:09.480 回答