开发者

embed dynamic image created from GD into email using PHP

开发者 https://www.devze.com 2023-03-17 18:09 出处:网络
For starters, I am using the following: php 5.3 PHPmailer - to send stmp email with google apps GD to create the iamge

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 remai开发者_运维知识库nder 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消