我必须为大学编制一个网站。 我对php的了解不太好(本学期开始)
我想创建一个pdf文件,在保存之后我想将它作为swiftmailer的附件发送。
以下是我编写的代码的一部分,用于发送带附件的邮件。
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 . "\n";
}
} else {
$mailtext .= $name . $trenner . $wert . "\n";
}
}
我得到的结果如下
消息ID:< 0e2c78549b70c6754d6213e28f27bc3b@dine.bronxx.org>日期:2015年12月20日星期日00:52:45 +0100主题:Rechnung FH门户网站:FH门户网站:na.racine@gmx.ch MIME-版本:1.0内容类型: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 ......“
编辑: 问题不在于我发布的代码。
// 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;
}
问题$result
为空。
由于echo $message;