将动态div图像发送到客户端邮件

时间:2016-06-28 23:35:51

标签: javascript php html html-email

我正在使用带条形码的html2canvas使用以下功能将动态图像制作到特定的div

$(function() { 
    $("#btnSave").click(function() { 
html2canvas($('#printableArea'), {
   onrendered: function(canvas) {
     var img = canvas.toDataURL()
     window.open(img);
}
                });
            });
        });

图像在base64中打开新的winodw 我的问题是我想将图像发送到客户端邮件进行打印。 相应地,每个客户的图像都会发生变化,具体是

我的php文件是

<?php
include("auth.php");
//message
$message = $_POST['msg'];
$username =$_REQUEST['username'];
$surname =$_REQUEST['surname'];
$name= $_REQUEST['name'];
//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
(http://panosmoustis.netai.net/barcodeimage/E-ticket_2016.pdf) .\n".

$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.";
}
?>

谢谢

1 个答案:

答案 0 :(得分:2)

您必须将图像数据发送到PHP脚本。这可以使用Javascript的XMLHTTPRequest来完成。由于您似乎使用的是jQuery,因此您也可以使用$.ajax

执行此操作

您可以发送原始base64编码的字符串,然后使用base64_decode在PHP端解码该字符串。然后你可以将它附加到电子邮件,这实际上很难实现。我建议使用一个库,因为有很多警告电子邮件附件。 SwiftMail或PHPMailer都很棒。

注意:如果使用PHPMailer,则不必使用base64_decode。 PHPMailer有一个方法AddStringAttachment