【问题标题】:Send dynamically div image to client mail [closed]将动态 div 图像发送到客户端邮件 [关闭]
【发布时间】:2016-10-31 11:22:18
【问题描述】:

我正在使用带有条形码的 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.";
}
?>

谢谢

【问题讨论】:

  • 那么问题是什么?见How to Ask
  • 我的问题是我想将图像发送到客户端邮件进行打印。
  • 你应该使用 PHPMailer,它让附件变得非常简单
  • @Zanderwar 当然...但是您知道 OP 是否甚至可以到达那里...不。具体问题没有提到。这就是要求 OP 提供适当的问题描述的意义......不仅仅是一个目标
  • 这是一个目标...不是与实现目标的代码相关的问题。这不是一个教程服务,问题需要定义一个特定代码相关问题

标签: javascript php html html-email


【解决方案1】:

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

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

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

【讨论】:

  • PHPMailer 有接受 base64 的 AddStringAttachment()
  • 更好!我不熟悉这种方法。更新以反映您的评论。
  • 能否提供代码?
  • @aristeidhsP 很抱歉,这有很多问题要问。我们已经为您指明了正确的方向,以及文档和调用的确切方法。请至少尝试一下。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-26
  • 1970-01-01
  • 1970-01-01
  • 2011-06-05
相关资源
最近更新 更多