I want to attach a file to an email. but the file fetches from a dynamic view. Is it possible?
Here is the code I have made in phpmailer.
$url = 'http://somewebsite.com/parameter';
$binary_content = file_get_contents($url);
if ($binary_content === false) {
throw new Exception("Could not fetch remote content from: '$url'");
}
$mail->AddStringAttachment($binary_content, "test.pdf", $encoding = 'base64', $type = 'application/pdf');
The code above successfully attached in the email. But the pdf file cannot be opened or an error.