2014-10-28 48 views
-2

單擊按鈕時,會生成PDF並在Web瀏覽器中打開PDF。我希望將pdf臨時存儲在變量中,並在點擊按鈕時將其作爲附件包含在郵件中。在php中創建併發送臨時pdf文件

我正在努力如何保存和附加文件。

<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]' . "\r\n" . 
    'Reply-To: [email protected]' . "\r\n" . 
    'X-Mailer: PHP/' . phpversion(); 
    mail($to, $subject, $message, $headers); 
?> 
+0

使用PHPMailer和它的AttachFromString方法(無論它被稱爲 - 它沒有在網站上明確記錄,但確實存在) – 2014-10-28 18:47:15

+0

或者上級[SwiftMailer](http://swiftmailer.org/)庫 – sjagr 2014-10-28 18:48:15

回答

1

就像在你的原帖評論說

使用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!"; 
} 
?> 

我編輯從網上房地產的快速這段代碼,認爲可以工作。與您調整每個變量。