2013-07-16 22 views
6

phpmailerを使用してメールを送信しています。私はpdfを生成するWebサービスを持っています。このpdfはどこにもアップロードまたはダウンロードしていません。私は私のメールにこのダイナミック PDFのURLを添付する必要が phpmailer動的URLからpdfを添付

http://mywebsite/webservices/report/sales_invoice.php?company=development&sale_id=2 

よう

PDFのURLがあります。 サービスURLを送る私の電子メールには、以下

http://mywebsite/webservices/mailservices/sales_email.php 

ようなもので、私はPDFファイルを添付するために使用していたコードです。

$pdf_url = "../report/sales_invoice.php?company=development&sale_id=2"; 
$mail->AddAttachment($pdf_url); 

送信メッセージは動作していますが、pdfは添付されていません。以下のメッセージが表示されます。

はファイルにアクセスできませんでした:phpmailerのよう

:../report/sales_invoice.php?company=development & sale_id = 2

私は

+6

私自身が答えを見つけました。以下はその解決策です。 $ string = file_get_contents( "http://mywebsite/report/sales_invoice.php?company = development&sale_id = 2"); $ mail-> AddStringAttachment($ string、 "sales_invoice.pdf"、$ encoding = 'base64'、$ type = 'application/pdf'); [PHPMailer AddAttachmentリモートファイル]の – Irawana

+0

の可能な複製(http://stackoverflow.com/questions/16485685/phpmailer-addattachment-remote-file) –

+2

解決策を「回答」に追加し、代わりに正解とする必要がありますコメントを追加する! – RPDeshaies

答えて

6

はここ答えを持ってするにはいくつかの助けが必要リモートコンテンツを自動取得しない場合は、自分で行う必要があります。

あなたが行くので:

// we can use file_get_contents to fetch binary data from a remote location 
$url = 'http://mywebsite/webservices/report/sales_invoice.php?company=development&sale_id=2'; 
$binary_content = file_get_contents($url); 

// You should perform a check to see if the content 
// was actually fetched. Use the === (strict) operator to 
// check $binary_content for false. 
if ($binary_content === false) { 
    throw new Exception("Could not fetch remote content from: '$url'"); 
} 

// $mail must have been created 
$mail->AddStringAttachment($binary_content, "sales_invoice.pdf", $encoding = 'base64', $type = 'application/pdf'); 

// continue building your mail object... 

に注意するためにいくつかの他のもの:サーバーの応答時間に応じて、

、あなたのスクリプトは、タイミングの問題に遭遇するかもしれません。また、取得されたデータがかなり大きくなる可能性があり、PHPがメモリ割り当てを超過する可能性があります。

+0

非常にありがたいです...($ url)の後にセミコロンを追加しました。これは完璧に機能します。 – felixmpa

関連する問題