首页 > 开发 > PHP > 正文

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

2024-05-04 23:01:49
字体:
来源:转载
供稿:网友
菜鸟学堂:
很实用的一个完整email发送程序,很简单,把下列代码复制到一个空白文本页面,如index.php,运行就行了。具体实例:http://zsvalley.uhome.net/email/index.php。
以下是完整的源代码:(有任何问题请email:[email protected]

<?

if ($ok=='yes'){
//        setcookie("yname", $yname);  
//        setcookie("yemail", $yemail);  

        if (!eregi("^[_.0-9a-z-][email protected]([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$",$yemail)){
             
            echo "请正确填写您的email地址! <a href='javascript:history.go(-1)'>返回</a>";
         
        }elseif(!eregi("^[_.0-9a-z-][email protected]([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$",$femail)){
         
            echo "请正确填写您好友的email地址! <a href='javascript:history.go(-1)'>返回</a>";

        }else{

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

            //email发送
            mail($femail, $title, $message,"from: $yemail");
//echo nl2br($message);
            $ok='no';
            echo "<html><body>".nl2br($message)."<br><br><a href=index.php>回到发送页面</a></body></html><script language="javascript">        alert("发送成功!"); </script>";

    }
    exit();
}
?>

<html>
<head>
<title>将网页推荐给好友</title>
<meta content="text/html; charset=gb2312" http-equiv=content-type>
<style type=text/css>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
}
</style>
<script language=javascript runat=server>
function check()
{
    if (document.frmsend.yname.value.length<1)
    {
        alert("请填写您的姓名!");
    }
    else if (document.frmsend.yemail.value.length<1)
    {
        alert("请填写您的email地址!");
    }
    else if (document.frmsend.fname.value.length<1)
    {
        alert("请填写您好友的姓名!");
    }
    else if (document.frmsend.femail.value.length<1)
    {
        alert("请填写您好友的email地址!");
    }
    else document.frmsend.submit();
}

//=====================dragon code===============================
function forhtmlspecialchars(str){ //将html中的特殊字符替换成代码
   str=strreplace(str,"&","&amp;");
   str=strreplace(str,""","&quot;");
   str=strreplace(str,"<","&lt;");
   str=strreplace(str,">","&gt;");
   str=strreplace(str,"%20"," ");
   return str;
}

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

function getparenttitle(){  //获取父页的标题
   str=location.href;
   str=str.substring(str.indexof("parenttitle"),str.indexof("parenttitleend"));
   str=str.substring(12,str.length);
   return str;
}
//======================================================
</script>
<meta content="mshtml 5.00.2920.0" name=generator>
</head>
<body bgcolor=white link=#ec9f00 text=#aa0000>
<center> <h3>快速email系统!</h3><form name=frmsend action=index.php method=post onsubmit="return check();">  
<input type="hidden" name="referer" value="<?echo $referer;?>"><input type="hidden" name="ok" value="yes"><input type="hidden" name="title" value="<?echo $parenttitle;?>"><table bgcolor=#e99b0a border=0 cellpadding=2 cellspacing=1>  
<tr> <td width="40%" height="22" bgcolor=#fdf4db>主题:</td><td width="40%" height="22" bgcolor=#fdf4db>  
<input class=st1 name="title" size="20" >
</td></tr> <tr> <td width="40%" height="10" bgcolor=#fdf4db></td><td width="60%" height="10" bgcolor="#fdf4db"></td></tr>  
<tr> <td width="40%" height="22" bgcolor=#fdf4db>您的姓名:</td><td width="60%" height="22" bgcolor=#fdf4db><input class=st1 name="yname" size="20" value=<?echo $yname?>></td></tr>  
<tr> <td width="40%" height="10" bgcolor=#fdf4db></td><td width="60%" height="10" bgcolor=#fdf4db></td></tr>  
<tr> <td width="40%" height="22" bgcolor=#fdf4db>邮件地址:</td><td width="60%" height="22" bgcolor=#fdf4db><input class=st1 name="yemail" size="20" value=<?echo $yemail?>></td></tr>  
<tr> <td width="40%" height="10" bgcolor=#fdf4db></td><td width="60%" height="10" bgcolor=#fdf4db></td></tr>  
<tr> <td width="40%" height="22" bgcolor=#fdf4db>朋友的姓名:</td><td width="60%" height="22" bgcolor=#fdf4db><input class=st1 name="fname" size="20" value=></td></tr>  
<tr> <td width="40%" height="10" bgcolor=#fdf4db></td><td width=60%height="10" bgcolor=#fdf4db></td></tr>  
<tr> <td width="40%" height="22" bgcolor=#fdf4db>邮件地址:</td><td width=60%height="22" bgcolor=#fdf4db><input class=st1 name="femail" size="20" value=></td></tr>  
<tr> <td width="40%" height="10" bgcolor=#fdf4db></td><td width=60%height="10" bgcolor=#fdf4db></td></tr>  
<tr> <td width="100%" height="22" bgcolor=#fdf4db colspan="2">您想说的话:</td></tr>  
<tr> <td width="100%" bgcolor=#fdf4db height="10" colspan="2"><textarea class=st1 rows="6" name="comments"
      cols="36"></textarea></td></tr> <tr> <td width="100%" colspan="2" bgcolor=#fdf4db><div align="center"><input type=button class=st2
      value="发送" name="send" onclick=check()></div></td></tr> </table></form></center><br><!--#51net -->
</body>
</html>  
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表