当前位置:首页> PHP教程> PHP入门
关键字
文章内容
生成图片E-mail地址
 
 
修改时间:[2011/08/30 01:32]    阅读次数:[991]    发表者:[起缘]
 

mail.php代码

<?
/*
MailX Managment System 0.8 Beta
*/
header("Content-type:image/png");
$mailaddress=$_GET['mailname'];
$mailaddresslen=strlen($mailaddress);
$mailaddressimages=imagecreate($mailaddresslen*10,25);
$lenadd=$mailaddresslen;
$fontsize="4";
$center=(imagesx($mailaddressimages)-8.3*strlen($mailaddress))/2;
$mailimagesbackground=ImageColorAllocate($mailaddressimages,255,255,255);
$mailimagesfacecolor=ImageColorAllocate($mailaddressimages,0,0,0);
ImageString($mailaddressimages,$fontsize,$center,5,$mailaddress,$mailimagesfacecolor);
Imagepng($mailaddressimages);
ImageDestroy($mailaddressimages);
?>

255,255,255 生成图片的背景颜色(RGB哦)
$fontsize="4";字体大小
($mailaddresslen*10,25);$mailaddresslen*10表示:生成图片宽:Email地址字符个数*10,25表示高

以上代码保存为mail.php 然后访问[email protected],就可以输出mailname=后面的邮件地址了.
当然,如果你嫌麻烦,可以用一个表单来代替.如下:

index.html代码如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" />
<head>
<title>Welcome to domain.com</title>
<meta http-equiv="Content-Language" content="en" />
</head>
<body>
<form action="mail.php" mothod="post">
You email:<input name="mailname" type="text" value="[email protected]" /><br /><input type="submit" value="确定" />
</form>