在PHP中创建并邮寄临时PDF [英] Create and mail temporary pdf in php
本文介绍了在PHP中创建并邮寄临时PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
单击按钮时,将生成pdf,并在网络浏览器中打开pdf.我希望将pdf临时存储在变量中,并在单击按钮时作为附件包含在邮件中.
When clicking the button a pdf is generated and opens the pdf in the web browser. I would like for the pdf to be stored temporary in a variable and included in mail as attachment when the buttons i clicked.
我正在努力保存和附加文件.
I'm struggling with how to save and attach the file.
<a class="button" href="http://mydomian.com/pdf001.php">Send PDF</a>
<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
推荐答案
就像您原始帖子下的评论所说
Like Comment under your original post say
使用PHPMailer
Use PHPMailer
<?php
require_once('../class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$mail->AddReplyTo("name@yourdomain.com","First Last");
$mail->SetFrom('name@yourdomain.com', 'First Last');
$mail->AddReplyTo("name@yourdomain.com","First Last");
$address = "whoto@otherdomain.com";
$mail->AddAddress($address, "John Doe");
$mail->Subject = "Php send pdf test";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AttachFromString (base64_encode(file_get_contents($urlToPdf))); // attachment
// in your case it would be http://mydomian.com/pdf001.php
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
我很快就从网上真正地编辑了此代码,并认为这可行.调整每个变量.
I edited this code from online real quick and think that could work. with your tweaking for each variable.
这篇关于在PHP中创建并邮寄临时PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文