我的代码创建一个pdf文件与fpdf,将安全的文件夹,称为“预订”。保存文件后,应使用phpmailer通过邮件将其发送给用户。
实际上,电子邮件将正确发送,但附件没有发送。
这是实际的代码,我现在试了一整天,但我没有任何运气:
$filename = 'Buchung-Nr.' . $booking_id . '.pdf';
$path = $system->SETTINGS['siteurl'] . 'bookings/';
$outputfile = 'bookings/Buchung-Nr.' . $booking_id . '.pdf';
$pdfout = $pdf->Output($outputfile, 'F');
$bodytext = 'Vielen Dank für Ihre Buchung';
require $include_path . 'phpmailer/src/Exception.php';
require $include_path . 'phpmailer/src/PHPMailer.php';
require $include_path . 'phpmailer/src/SMTP.php';
$mail = new PHPMailer();
$replytotext = 'Ostsee-Deluxe - Buchung-Nr.' . $booking_id;
try {
//Server settings
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'sslout.df.eu'; //Set the SMTP server to send through
$mail->SMTPSecure = "TLS";
$mail->SMTPAuth = true;
$mail->CharSet = 'UTF-8'; //Enable SMTP authentication
$mail->Username = 'USERNAME-HIDDEN'; //SMTP username
$mail->Password = 'PW-HIDDEN'; //SMTP password
$mail->Port = 25; //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('kontakt@ostsee-deluxe.com', 'Ostsee-Deluxe');
$mail->addAddress($email, $fullname); //Add a recipient
$mail->addReplyTo('kontakt@ostsee-deluxe.com', $replytotext);
$mail->addBCC('kontakt@ostsee-deluxe.com');
//Attachments
$mail->addAttachment($path/$filename); //Optional name
var_dump($path,$filename);
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'Buchungs-Nr. ' . $booking_id;
$mail->Body = $bodytext;
$mail->AltBody = $bodytext_alt;
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}我可以打开新创建的pdf附件,每次在文件夹中,但附件在电子邮件是空的。
你有什么解决办法吗?
编辑:哦,好主意,谢谢你,我现在收到了!我改变了:
$path = $system->SETTINGS['siteurl'] . 'bookings/'; to $path = 'bookings/';和
$mail->addAttachment($path . $filename); //Optional name现在起作用了,谢谢您@Akshay Hedge和Sven Eberth!去年我被否决了,但是这次你们对这个基本问题都很好,坚持下去!:)
发布于 2021-05-27 18:29:18
我认为
$mail->addAttachment($path/$filename);应该是
$mail->addAttachment($path . $filename);否则,将路径除以文件名。
发布于 2021-05-27 18:39:14
使用双引号,然后它将工作的路径和文件存在。
从…
$mail->addAttachment($path/$filename);至
$mail->addAttachment("$path/$filename");https://stackoverflow.com/questions/67727856
复制相似问题