Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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' . "
" .
     'Reply-To: webmaster@example.com' . "
" .
     'X-Mailer: PHP/' . phpversion();
     mail($to, $subject, $message, $headers);
?>
See Question&Answers more detail:os

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

1 Answer

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("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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...