【问题标题】:JavaBridge BIRT Send EmailJavaBridge BIRT 发送电子邮件
【发布时间】:2016-09-09 05:54:33
【问题描述】:

我的 php 代码需要一些帮助。我的报告是在 eclipse BIRT 中完成的,给他们一个 .rptdesign 文件扩展名,我想通过 gmail 发送它。我发送成功,但图像已损坏且未应用 CSS。这是我的代码

<html>
    <body>
    <hr>
        <form action="PhpRunAndRenderHTMLEmbed.php" method="POST">
            <input type="submit" name="submit" value="SEND">
        </form>
    <hr>
    </body>
</html>
<?php

if (!(get_cfg_var('java.web_inf_dir'))) {
  define ("JAVA_HOSTS", "127.0.0.1:8080");
  define ("JAVA_SERVLET", "/JavaBridge/JavaBridge.phpjavabridge");
}
$pth = "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"];
$path_parts = pathinfo($pth);
$imageURLPrefix = $path_parts['dirname'] ."/sessionChartImages/";
require_once("java/Java.inc");

session_start(); 

$here = getcwd();

$ctx = java_context()->getServletContext();
$birtReportEngine =        java("org.eclipse.birt.php.birtengine.BirtEngine")->getBirtEngine($ctx);
java_context()->onShutdown(java("org.eclipse.birt.php.birtengine.BirtEngine")->getShutdownHook());


try{


$report = $birtReportEngine->openReportDesign("${here}/TopNPercent.rptdesign");
$task = $birtReportEngine->createRunAndRenderTask($report);
$taskOptions = new java("org.eclipse.birt.report.engine.api.HTMLRenderOption");
$outputStream = new java("java.io.ByteArrayOutputStream");
$taskOptions->setOutputStream($outputStream);
$taskOptions->setEmbeddable(true);
$taskOptions->setOutputFormat("html");
$ih = new java( "org.eclipse.birt.report.engine.api.HTMLServerImageHandler");
$taskOptions->setImageHandler($ih);
$taskOptions->setEnableAgentStyleEngine(true);
$taskOptions->setBaseImageURL($imageURLPrefix . session_id());
$taskOptions->setImageDirectory($here . "/sessionChartImages/" . session_id());

$task->setRenderOption( $taskOptions );
$task->run();
$task->close();

} catch (JavaException $e) {
    echo $e; //"Error Calling BIRT";

}
echo $outputStream;

if(isset($_POST['submit'])){
    require 'PHPMailer/PHPMailerAutoload.php';

    $mail = new PHPMailer;

    $mail->isSMTP();                                   // Set mailer to use SMTP
    $mail->Host = 'smtp.gmail.com';                    // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                            // Enable SMTP authentication
    $mail->Username = 'sample@gmail.com';          // SMTP username
    $mail->Password = 'password'; // SMTP password
    $mail->SMTPSecure = 'tls';                         // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                 // TCP port to connect to

    $mail->setFrom('sample@gmail.com', 'sample');
    $mail->addReplyTo('sample@gmail.com', 'sample');
    $mail->addAddress('sample@gmail.com');   // Add a recipient

    $mail->isHTML(true);  // Set email format to HTML


    $bodyContent = '<p>This is the HTML email sent from localhost using PHP</p>';

    $src = 'C:\xampp\htdocs\JavaBridge\sessionChartImages\6th1i2ih8j1r83o21iidi1qte0\custom6ab9ab811570c80985d2.png';
    $mail->AddEmbeddedImage($src, 'chart_image', 'custom6ab9ab811570c80985d2.png');

    $mail->Subject = 'BIRT PHP Email';
    $bodyContent .= $outputStream;
    $mail->Body = $bodyContent;


    if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message has been sent';
    }
}


?>

我该怎么办?

【问题讨论】:

    标签: php phpmailer birt php-java-bridge


    【解决方案1】:

    发送过程与 CSS 没有任何关系 - 这完全取决于客户端,但请记住,电子邮件客户端中的 CSS 支持非常多变,并且您不能使用外部样式表。很难说,因为您没有显示您的消息正文中的内容。

    当你说图像坏了,你是什么意思?

    要引用嵌入图像,您需要引用其cid,例如:

    <img src="cid:chart_image" />
    

    【讨论】:

    • 图片未显示。它只显示损坏的图像图标。由于 JavaBridge 有一个示例 PhpRunAndRenderHTMLEmbed.php 文件,因此它将整个报告呈现为 HTML 并在浏览器中显示。但是当我尝试发送包含渲染报告的电子邮件时,图像未显示
    【解决方案2】:

    将图形报告作为 PDF 格式的附件发送更有意义。

    【讨论】:

      猜你喜欢
      • 2011-09-16
      • 1970-01-01
      • 2012-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-30
      相关资源
      最近更新 更多