0

I'm using PHPMailer. I have to send two attachments and both are links (one is base64 image and the second one is url).

// Variables with images
$croped_img = 'data:image/jpg;base64,/extreme_long_code_here';
$photo_thumbnail_url = 'http://t2.ftcdn.net/jpg/00/76/44/75/400_F_76447580_gOWAV0P8APW0iC51OsW5huD6qoiEsh7O.jpg';

// PHPMailer
$mail->addAttachment('$photo_thumbnail_url', 'selected.jpg');
$mail->addAttachment('$croped_img', 'croped_img.jpg');

PHPMailer works because if I send e-mail in that form, attachments do not come. But if I link local image e.g. 'images/abc.jpg' then they comes.

What php functions should I use to send my variables as e-mail attachments?

3
  • You sould use the method AddEmbeddedImage Commented Feb 23, 2015 at 12:06
  • But how to use this in my case? I'm still trying but It wont work for me. Commented Feb 23, 2015 at 12:43
  • possible duplicate of Php attachment from string Commented Feb 23, 2015 at 13:46

2 Answers 2

4

As always, make sure you're using a recent version of PHPMailer.

You need to use addStringAttachment, docs here:

$photo_thumbnail_url = 'http://t2.ftcdn.net/jpg/00/76/44/75/400_F_76447580_gOWAV0P8APW0iC51OsW5huD6qoiEsh7O.jpg';
$mail->addStringAttachment(file_get_contents($photo_thumbnail_url), 'selected.jpg');

The msgHTML function handles data URLs automatically, converting them to embedded images with automatic cid values, so if your image is already embedded in your HTML, you don't have to do anything for it to work.

If you want to handle data URL conversion yourself, you can see how it works here.

Sign up to request clarification or add additional context in comments.

Comments

0

Make SURE that your PHPMailer library is up-to-date!

and then try this one,

$mail->AddEmbeddedImage($photo_thumbnail_url, 'selected.jpg');
$mail->AddEmbeddedImage($croped_img, 'croped_img.jpg');

1 Comment

It's doesn't work. I would like to attach instead of embed. In documentation I found this: AddAttachment($path,$name,$encoding,$type); but It still won't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.