dpstir0081 2011-07-05 22:17
浏览 39
已采纳

使用PHP将从GD创建的动态图像嵌入到电子邮件中

For starters, I am using the following:

  • php 5.3
  • PHPmailer - to send stmp email with google apps
  • GD to create the iamge

  • I am able to take a previously existing file, add text to that file and output to a browser.

  • I am able to send email with an existing embedded image using simple functions within phpmailer
  • I am NOT able to dynamically modify the first file, have it saved in memory, then embed THAT image in my email.

When creating my image, I am using a very basic sample script:

EDIT

I modified my code to the following: seems to run faster as well as easier to read. An actual file is created however whereas I would prefer a temporary file I could destroy after or simply use binary data. Is there a binary output function similar to imagegif()?

$photo = imagecreatefromgif('sample.gif');
imagealphablending($photo, true);
$fontsize = 20;
$font = '../times.ttf';
$fontcolor = imagecolorallocate($photo, 0, 0, 0);
$angle = 0;
$x = 100;
$y = 100;
$text = 'THIS IS A BLOB OF TEXT YO!';
imagettftext($photo, $fontsize, $angle, $x, $y, $fontcolor, $font, $text);
imagegif($photo, 'test.gif');

unfortunately, this wants to output my file to the browser, then proceed with the remainder of the script and send the email (without embedded image).

I know I am probably missing something simple but has anybody run into this issue before?

  • 写回答

1条回答 默认 最新

  • duanemei2194 2011-07-05 22:23
    关注

    Firstly you need to a) save the image to temporary file using second argument of imagegif function; b) use PHP output buffering to capture the result sent to output and clean it from the response (see http://php.net/ob).

    Afterwards you need to know how to embed the image as attachment to the email letter or copy it as real file with http address available and point the <img href=""/> to it.

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

报告相同问题?

悬赏问题

  • ¥15 怎样才能让鼠标沿着线条的中心线轨迹移动
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?