Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
252 views
in Technique[技术] by (71.8m points)

email - Create and mail temporary pdf in php

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      = '[email protected]';
     $subject = 'the subject';
     $message = 'hello';
     $headers = 'From: [email protected]' . "
" .
     'Reply-To: [email protected]' . "
" .
     'X-Mailer: PHP/' . phpversion();
     mail($to, $subject, $message, $headers);
?>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Like Comment under your original post say

Use PHPMailer

<?php
require_once('../class.phpmailer.php');

$mail             = new PHPMailer(); // defaults to using php "mail()"

$mail->AddReplyTo("[email protected]","First Last");

$mail->SetFrom('[email protected]', 'First Last');

$mail->AddReplyTo("[email protected]","First Last");

$address = "[email protected]";
$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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...