0

Currently im using phpmailer and using AddEmbeddedImage. This web is using different data source from two server. http://10.99.09.1/ and http://10.99.99.2 this example. SO current my web is hosted under http://10.99.99.2 and all script is run from http://10.99.99.2 mean while when i using phpmailer and try to call the images from server http://10.99.99.1 it doesnt work

$imagescontent='http://10.99.09.1/port/upload/file/'.$line["fil_id"].'.png';
$mail->AddEmbeddedImage($imagescontent, "my-attach", $imagescontent);

but when i try to fetch the images from the same server when the script is hosted its works. Any idea to make this things works where i can fetch the images from other server

parkway
  • 276
  • 1
  • 15
  • Can you grab the file itself without directly sending it? If so; you could download the image to a temp dir, then use it's path to send the image as attachment and after sending(success) remove the TMP file. – GRX Sep 20 '19 at 07:20
  • what do you mean by grab the file itself without directly sending it? – parkway Sep 20 '19 at 07:21
  • https://stackoverflow.com/questions/724391/saving-image-from-php-url from this example use the `$img` as attachment. – GRX Sep 20 '19 at 07:24
  • nice trick. thanks for the that lovely trick – parkway Sep 20 '19 at 07:37

1 Answers1

0

No, you can't do this directly. PHPMailer deliberately avoids acting as an HTTP client because that's not what it's for, but there are many other functions, packages, and utilities that can help you with that. Most straightforwardly:

$imagescontent= file_get_contents('http://10.99.09.1/port/upload/file/'.$line['fil_id'].'.png');
$mail->addStringEmbeddedImage($imagescontent, "my-attach", $line['fil_id'].'.png');

Of course there are many things that can cause that file_get_contents call to fail, and myriad ways that you might want to control how it operates, such as providing authentication, using a proxy, requesting a particular format via an Accept header - and that's exactly why PHPMailer doesn't want to be responsible for that - it's an email client, not an HTTP client.

Synchro
  • 35,538
  • 15
  • 81
  • 104