duanhunlou7051 2015-02-23 11:59
浏览 150


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?

  • 写回答

2条回答 默认 最新

  • dos49618 2015-02-23 13:59

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
  • dongzongzhi6953 2015-02-23 13:12

    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');



  • ¥20 powerbulider 导入excel文件,显示不完整
  • ¥20 #关于multisim绘图遇到的问题
  • ¥15 用keil调试程序保证结果进行led相关闪烁
  • ¥15 paddle训练自己的数据loss降不下去
  • ¥20 用matlab的pdetool解决以下三个问题
  • ¥15 单个福来轮的平衡与侧向滑动是如何做到的?
  • ¥15 嵌入式Linux固件,能直接告诉我crc32校验的区域在哪不,内核的校验我已经找到了,uboot没有
  • ¥20 h3c静态路要求有详细过程
  • ¥15 调制识别中输入为时频图,星座图,眼图等
  • ¥15 数据结构C++的循环、随机数问题