很实用的一个完整email发送程序

2000-12-22 10:35:42  作者
很实用的一个完整email发送程序,很简单,把下列代码复制到一个空白文本页面,如index.php,运行就行了。具体实例http://zsvalley.uhome.net/email/index.php。
以下是完整的源代码(有任何问题请emailzsvalley@cmmail.com)

%26lt;?

if ($ok=='yes'){
//SetCookie(%26quot;yname%26quot;, $yname);
//SetCookie(%26quot;yemail%26quot;, $yemail);

if (!eregi(%26quot;^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$%26quot;,$yemail)){

echo %26quot;请正确填写您的EMAIL地址! %26lt;A HREF='javascript:history.go(-1)'%26gt;返回%26lt;/A%26gt;%26quot;;

}elseif(!eregi(%26quot;^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$%26quot;,$femail)){

echo %26quot;请正确填写您好友的EMAIL地址! %26lt;A HREF='javascript:history.go(-1)'%26gt;返回%26lt;/A%26gt;%26quot;;

}else{

$message=$fname.%26quot;,你好:nn你的朋友%26quot;.$yname.%26quot;特地来信想对向您说:n-----------------------------------n%26quot;.$comments.%26quot;n-----------------------------------nnn提供服务http://zsvalley.uhome.net/email/nn◆◆◆ valley网络无界限http://valley.coc.cc ◆◆◆n─────────────────────────n%26quot;;

//email发送
mail($femail, $title, $message,%26quot;From: $yemail%26quot;);
//echo nl2br($message);
$ok='no';
echo %26quot;%26lt;html%26gt;%26lt;body%26gt;%26quot;.nl2br($message).%26quot;%26lt;BR%26gt;%26lt;BR%26gt;%26lt;A HREF=index.php%26gt;回到发送页面%26lt;/A%26gt;%26lt;/body%26gt;%26lt;/html%26gt;%26lt;script language=%26quot;javascript%26quot;%26gt;alert(%26quot;发送成功!%26quot;); %26lt;/script%26gt;%26quot;;

}
exit();
}
?%26gt;

%26lt;html%26gt;
%26lt;head%26gt;
%26lt;TITLE%26gt;将网页推荐给好友%26lt;/TITLE%26gt;
%26lt;META content=%26quot;text/html; charset=gb2312%26quot; http-equiv=Content-Type%26gt;
%26lt;STYLE type=text/css%26gt;BODY {
FONT-SIZE: 14px; LINE-HEIGHT: 18px
}
TD {
FONT-SIZE: 14px; LINE-HEIGHT: 18px
}
.st1 {
BACKGROUND-COLOR: #ffcc66; BORDER-BOTTOM: #ffcc66 1px solid; BORDER-LEFT: #ffcc66 1px solid; BORDER-RIGHT: #ffcc66 1px solid; BORDER-TOP: #ffcc66 1px solid; COLOR: #aa0000; FONT-SIZE: 9pt
}
.st2 {
BACKGROUND-COLOR: #ffcc66; BORDER-BOTTOM: #ec9f00 1px solid; BORDER-LEFT: #ffffff 1px solid; BORDER-RIGHT: #ec9f00 1px solid; BORDER-TOP: #ffffff 1px solid; COLOR: #aa0000; FONT-SIZE: 9pt; HEIGHT: 20px; WIDTH: 60px
}
%26lt;/STYLE%26gt;
%26lt;script language=JavaScript runat=Server%26gt;
function check()
{
if (document.frmSend.yname.value.length%26lt;1)
{
alert(%26quot;请填写您的姓名!%26quot;);
}
else if (document.frmSend.yemail.value.length%26lt;1)
{
alert(%26quot;请填写您的EMAIL地址!%26quot;);
}
else if (document.frmSend.fname.value.length%26lt;1)
{
alert(%26quot;请填写您好友的姓名!%26quot;);
}
else if (document.frmSend.femail.value.length%26lt;1)
{
alert(%26quot;请填写您好友的EMAIL地址!%26quot;);
}
else document.frmSend.submit();
}

//=====================DRAGON CODE===============================
function forHtmlSpecialChars(str){ //将HTML中的非凡字符替换成代码
str=strReplace(str,%26quot;%26amp;%26quot;,%26quot;%26amp;amp;%26quot;);
str=strReplace(str,%26quot;%26quot;%26quot;,%26quot;%26amp;quot;%26quot;);
str=strReplace(str,%26quot;%26lt;%26quot;,%26quot;%26amp;lt;%26quot;);
str=strReplace(str,%26quot;%26gt;%26quot;,%26quot;%26amp;gt;%26quot;);
str=strReplace(str,%26quot;%20%26quot;,%26quot; %26quot;);
return str;
}

function strReplace(str,str1,str2){ //将str中的所有str1替换城str2
while(str.search(str1)%26gt;-1)
str=str.replace(str1,str2);
return str;
}

function getParentTitle(){//获取父页的标题
str=location.href;
str=str.substring(str.indexOf(%26quot;parentTitle%26quot;),str.indexOf(%26quot;parentTitleEnd%26quot;));
str=str.substring(12,str.length);
return str;
}
//======================================================
%26lt;/script%26gt;
%26lt;META content=%26quot;MSHTML 5.00.2920.0%26quot; name=GENERATOR%26gt;
%26lt;/head%26gt;
%26lt;body bgColor=white link=#ec9f00 text=#aa0000%26gt;
%26lt;center%26gt; %26lt;H3%26gt;快速email系统!%26lt;/H3%26gt;%26lt;FORM name=frmSend ACTION=index.php METHOD=POST onsubmit=%26quot;return check();%26quot;%26gt;
%26lt;INPUT TYPE=%26quot;hidden%26quot; NAME=%26quot;referer%26quot; value=%26quot;%26lt;?echo $referer;?%26gt;%26quot;%26gt;%26lt;INPUT TYPE=%26quot;hidden%26quot; NAME=%26quot;ok%26quot; VALUE=%26quot;yes%26quot;%26gt;%26lt;INPUT TYPE=%26quot;hidden%26quot; NAME=%26quot;title%26quot; VALUE=%26quot;%26lt;?echo $parentTitle;?%26gt;%26quot;%26gt;%26lt;table bgColor=#e99b0a border=0 cellPadding=2 cellSpacing=1%26gt;
%26lt;tr%26gt; %26lt;td width=%26quot;40%%26quot; height=%26quot;22%26quot; bgColor=#fdf4db%26gt;主题%26lt;/td%26gt;%26lt;td width=%26quot;40%%26quot; height=%26quot;22%26quot; bgcolor=#fdf4db%26gt;
%26lt;input class=st1 name=%26quot;title%26quot; size=%26quot;20%26quot; %26gt;
%26lt;/td%26gt;%26lt;/tr%26gt; %26lt;tr%26gt; %26lt;td width=%26quot;40%%26quot; height=%26quot;10%26quot; bgColor=#fdf4db%26gt;%26lt;/td%26gt;%26lt;td width=%26quot;60%%26quot; height=%26quot;10%26quot; bgcolor=%26quot;#fdf4db%26quot;%26gt;%26lt;/td%26gt;%26lt;/tr%26gt;
%26lt;tr%26gt; %26lt;td width=%26quot;40%%26quot; height=%26quot;22%26quot; bgColor=#fdf4db%26gt;您的姓名%26lt;/td%26gt;%26lt;td width=%26quot;60%%26quot; height=%26quot;22%26quot; bgcolor=#fdf4db%26gt;%26lt;input class=st1 name=%26quot;yname%26quot; size=%26quot;20%26quot; value=%26lt;?echo $yname?%26gt;%26gt;%26lt;/td%26gt;%26lt;/tr%26gt;
%26lt;tr%26gt; %26lt;td width=%26quot;40%%26quot; height=%26quot;10%26quot; bgcolor=#fdf4db%26gt;%26lt;/td%26gt;%26lt;td width=%26quot;60%%26quot; height=%26quot;10%26quot; bgcolor=#fdf4db%26gt;%26lt;/td%26gt;%26lt;/tr%26gt;
%26lt;tr%26gt; %26lt;td width=%26quot;40%%26quot; height=%26quot;22%26quot; bgcolor=#fdf4db%26gt;邮件地址%26lt;/td%26gt;%26lt;td width=%26quot;60%%26quot; height=%26quot;22%26quot; bgcolor=#fdf4db%26gt;%26lt;input class=st1 name=%26quot;yemail%26quot; size=%26quot;20%26quot; value=%26lt;?echo $yemail?%26gt;%26gt;%26lt;/td%26gt;%26lt;/tr%26gt;
%26lt;tr%26gt; %26lt;td width=%26quot;40%%26quot; height=%26quot;10%26quot; bgcolor=#fdf4db%26gt;%26lt;/td%26gt;%26lt;td width=%26quot;60%%26quot; height=%26quot;10%26quot; bgcolor=#fdf4db%26gt;%26lt;/td%26gt;%26lt;/tr%26gt;
%26lt;tr%26gt; %26lt;td width=%26quot;40%%26quot; height=%26quot;22%26quot; bgcolor=#fdf4db%26gt;朋友的姓名%26lt;/td%26gt;%26lt;td width=%26quot;60%%26quot; height=%26quot;22%26quot; bgcolor=#fdf4db%26gt;%26lt;input class=st1 name=%26quot;fname%26quot; size=%26quot;20%26quot; value=%26gt;%26lt;/td%26gt;%26lt;/tr%26gt;
%26lt;tr%26gt; %26lt;td width=%26quot;40%%26quot; height=%26quot;10%26quot; bgcolor=#fdf4db%26gt;%26lt;/td%26gt;%26lt;td width=60%height=%26quot;10%26quot; bgcolor=#fdf4db%26gt;%26lt;/td%26gt;%26lt;/tr%26gt;
%26lt;tr%26gt; %26lt;td width=%26quot;40%%26quot; height=%26quot;22%26quot; bgcolor=#fdf4db%26gt;邮件地址%26lt;/td%26gt;%26lt;td width=60%height=%26quot;22%26quot; bgcolor=#fdf4db%26gt;%26lt;input class=st1 name=%26quot;femail%26quot; size=%26quot;20%26quot; value=%26gt;%26lt;/td%26gt;%26lt;/tr%26gt;
%26lt;tr%26gt; %26lt;td width=%26quot;40%%26quot; height=%26quot;10%26quot; bgcolor=#fdf4db%26gt;%26lt;/td%26gt;%26lt;td width=60%height=%26quot;10%26quot; bgcolor=#fdf4db%26gt;%26lt;/td%26gt;%26lt;/tr%26gt;
%26lt;tr%26gt; %26lt;td width=%26quot;100%%26quot; height=%26quot;22%26quot; bgcolor=#fdf4db colspan=%26quot;2%26quot;%26gt;您想说的话%26lt;/td%26gt;%26lt;/tr%26gt;
%26lt;tr%26gt; %26lt;td width=%26quot;100%%26quot; bgcolor=#fdf4db height=%26quot;10%26quot; colspan=%26quot;2%26quot;%26gt;%26lt;textarea class=st1 rows=%26quot;6%26quot; name=%26quot;comments%26quot;
cols=%26quot;36%26quot;%26gt;%26lt;/textarea%26gt;%26lt;/td%26gt;%26lt;/tr%26gt; %26lt;tr%26gt; %26lt;td width=%26quot;100%%26quot; colspan=%26quot;2%26quot; bgcolor=#fdf4db%26gt;%26lt;div align=%26quot;center%26quot;%26gt;%26lt;INPUT TYPE=button CLASS=st2
VALUE=%26quot;发送%26quot; NAME=%26quot;send%26quot; ONCLICK=check()%26gt;%26lt;/div%26gt;%26lt;/td%26gt;%26lt;/tr%26gt; %26lt;/table%26gt;%26lt;/form%26gt;%26lt;/center%26gt;%26lt;BR%26gt;%26lt;!--#51Net --%26gt;
%26lt;/body%26gt;
%26lt;/html%26gt;