To get the answer right here:
Since phpmailer will not automatically retrieve remote content, you need to do it yourself.
So you go:
// 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...
Some other things to consider:
Depending on the server response time, your script may run into time problems. In addition, the extracted data can be quite large and can lead to php exceeding the memory allocation.
source share