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


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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 帮我解决一下膳食平衡的线性规划模型的数据实例
  • ¥40 万年历缺少农历,需要和阳历同时显示
  • ¥250 雷电模拟器内存穿透、寻基址和特征码的教学
  • ¥200 比特币ord程序wallet_constructor.rs文件支持一次性铸造1000个代币,并将它们分配到40个UTXO上(每个UTXO上分配25个代币),并设置找零地址
  • ¥15 关于Java的学习问题
  • ¥15 如何使用chatgpt完成文本分类任务?
  • ¥15 已知速度v关于位置s的等式,怎么转化为已知位置求速度v的等式
  • ¥15 我有个餐饮系统,用wampserver把环境配置好了,但是后端的网页却进去,是为什么,能不能帮远程一下?
  • ¥15 R运行没有名称为"species"的插槽对于此对象类"SDMmodelCV"
  • ¥20 基于决策树的数字信号处理,2ask 2psk 2fsk的代码,检查下报错的原因