doujiao3016 2015-01-17 22:30
浏览 43
已采纳

由phpmailer中的API生成的png附件

I'm trying to send a .png image to my user via phpmailer. The image is shown when I use <img> tags, but I want it to display as a real attachment that the user can open/save/print (like in this screenshot). I read that I can use $mail->addStringAttachment for this. So I tried this, and it does send an attachment with the email, but when I try to open it, it says that Windows Picture Viewer can't open the file. Also saving to my computer and then opening with Paint doesn't work, it tells me thats not a valid file or something. I think this is because it's no static image, but an image generated by an API, namely:

$qr = 'http://api.qrserver.com/v1/create-qr-code/?data=' . $guid . '&size=250x250';

So this image should be sent as an attachment. Does anyone know how I can make this work?

  • 写回答

2条回答 默认 最新

  • dqt66847 2015-01-17 23:56
    关注

    The reason it's failing is that you're trying to attach the URL as image data. You need to fetch the data from the URL first, then attach it to something.

    Go one step at a time - make sure that you're getting back valid image before trying to email it - e.g.

    file_put_contents('qr.png', file_get_contents($qr));
    

    and make sure you get a valid image saved in there. When you know that's working, then try and email it with

    $mail->addStringAttachment(file_get_contents($qr) 'qr.png');
    

    Though perhaps with a bit more error checking!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ADS生成的微带线为什么是蓝色空心的
  • ¥15 求一下解题思路,完全不懂
  • ¥15 tensorflow
  • ¥15 densenet网络结构中,特征以cat方式复用后是怎么进行误差回传的
  • ¥15 STM32G471芯片spi设置了8位,总是发送16位
  • ¥15 R语言并行计算beta-NTI中tree文件的类型
  • ¥15 如何解读marsbar导出的ROI数据?
  • ¥20 求友友协助弄一下基于STC89C52单片机的声光控制灯原理图
  • ¥15 arduino双向交通灯设计
  • ¥15 有没有会粒子群算法的大能(○゜ε^○)求带不会出收敛图😭