我正在尝试在我的自定义 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 和其他信息,而不仅仅是一个。
提前致谢。