将邮件生成图片

为了防止邮箱收到spam,可以将邮件地址生成图片。

程序如下:

  1. < ?php
  2. header("Content-type:image/png");
  3. $mailaddress=$_GET&#91;'mailname'];
  4. $mailaddresslen=strlen($mailaddress);
  5. $mailaddressimages=imagecreate($mailaddresslen*10,25);
  6. $lenadd=$mailaddresslen;
  7. $fontsize="4";
  8. $center=(imagesx($mailaddressimages)-8.3*strlen($mailaddress))/2;
  9. $mailimagesbackground=ImageColorAllocate($mailaddressimages,255,255,255);
  10. $mailimagesfacecolor=ImageColorAllocate($mailaddressimages,0,0,0);
  11. ImageString($mailaddressimages,$fontsize,$center,5,$mailaddress,$mailimagesfacecolor);
  12. Imagepng($mailaddressimages);
  13. ImageDestroy($mailaddressimages);
  14. ?>

:255,255,255 是背景的颜色,保存为mai.php

  1. < !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" />
  3. <head>
  4. <title>Creat Your Email Images</title>
  5. <meta http-equiv="Content-Language" content="en" />
  6. </head>
  7. <body>
  8. <form action="mail.php" mothod="post">
  9. You email:<input name="mailname" type="text" value="you@domain.com" /><br /><input type="submit" value="确定" />
  10. </form>
  11. </body>

保存为mail.html

演示效果:

email,图片

发表评论

电子邮件地址不会被公开。 必填项已用*标注