doulu8446 2015-12-20 07:53
浏览 27

无法使用swiftmailer发送fpdf(php)

I have to programm a website for university. My knowledge about php is not so good (started this semester)

I want to create a pdf file and after I saved it I want to send it as an attachment with swiftmailer.

Here is a part of my code which I wrote to send the mail with attachment.

require_once "../swiftmailer/lib/swift_required.php"; // Swift initialisieren

include('../credentials.php');
// Create the attachment with your data
$attachment = Swift_Attachment::fromPath("Rechnung_".$_SESSION['refn'].".pdf", "application/pdf");
if ($_SERVER['REQUEST_METHOD'] === "GET") {

$message = Swift_Message::newInstance(); // Ein Objekt für die Mailnachricht

$message
->setFrom(array($absenderadresse => $absendername))
->setTo(array($zieladresse))
->setSubject($betreff)
->attach ($attachment)
->setBody(
"random text");

$mailtext = "";

foreach ($_POST as $name => $wert) {
if (is_array($wert)) {
foreach ($wert as $einzelwert) {
$mailtext .= $name . $trenner . $einzelwert . "
";
}
} else {
$mailtext .= $name . $trenner . $wert . "
";
}
}

The result I get is the following

Message-ID: <0e2c78549b70c6754d6213e28f27bc3b@dine.bronxx.org> Date: Sun, 20 Dec 2015 00:52:45 +0100 Subject: Rechnung FH Portal From: FH Portal To: na.racine@gmx.ch MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="_=_swift_v4_1450569165_894d353ae292b94f0887df24da701f46_=" --=_swift_v4_1450569165_894d353ae292b94f0887df24da701f46_=_ Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable ... --_=_swift_v4_1450569165_894d353ae292b94f0887df24da701f46_=_ Content-Type: application/pdf; name=Rechnung_5000000004.pdf Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=Rechnung_5000000004.pdf JVBERi0xLjM..."

EDIT: The problem is not the code i posted bevore.

// Echo Logger aktivieren (es gibt noch einen logger der auf File schreibt)
$logger = new Swift_Plugins_Loggers_EchoLogger();
$mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));

echo $message;
$result = $mailer->send($message);
} catch (Exception $e) {
$error_log = $logger->dump();
}

if ($result == 0) {
die("Mail konnte nicht versandt werden.");
}

header("Location: $urlDankeSeite");
exit;
}

It is the problem that $result is empty. I had the output because of echo $message;

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog