duanhunlou7051 2015-02-23 11:59
浏览 151
已采纳

通过PHPMailer发送带有URL附件的电子邮件

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.

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

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀