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;