亿网中国提供全程无忧网站建设服务!
Individuals网站建设
   Website Design
Individuals成功案例
   Classic case example
Individuals酷站欣赏
   Cool Website Enjoy

网站建设-价格体系

网站建设-建站流程

本站动态
实用ASP/PHP如何直接提交表单到指定邮箱的方法
 
时间:2011-8-30 8:25:16

ASP/PHP如何直接提交表单到指定邮箱的方法 实用

如果在不知道服务器支持的email组件是什么,可以把阿江探针下载下来.通过FTP传到空间里.

[阿江探针下载地址] http://www.ajiang.net/article/artview.asp?id=346

然后打开阿江探针这个网,一般是aspcheck.asp

即可看到服务器支持的email组件有哪些.

支持JMail的示例:

message.asp 页

<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<form name="form_mess" method="post" action="send.asp" OnSubmit="return check();">
<tr bgcolor="#FFFFFF">
<td height="25" class="text_12pix_of_20pix"><div align="right">您的姓名:</div></td>
<td><input name="name" type="text" size="14"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="25" class="text_12pix_of_20pix"><div align="right">您的Email:</div></td>
<td><input name="email" type="text" size="20"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="25" class="text_12pix_of_20pix"><div align="right">您的电话:</div></td>
<td><input name="tel" type="text" size="20"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="25" class="text_12pix_of_20pix"><div align="right">其他联系方式:</div></td>
<td><input name="other" type="text" size="40"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="19%" height="25" class="text_12pix_of_20pix"><div align="right">邮件标题:</div></td>
<td width="81%">
<input name="title" type="text" size="40"> <font color="#ff0000">*</font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="25" class="text_12pix_of_20pix"><div align="right">邮件内容:</div></td>
<td><textarea name="content" cols="40" rows="12" wrap="VIRTUAL"></textarea> <font color="#ff0000">*</font></td>
</tr>
<%
'----------------------获取验证代码----------------------
Function GetValidateCode()
Randomize Timer '产生一个随机树
GetValidateCode=Left(Int(Rnd*9998)+1000,4)
If Len(GetValidateCode)>4 Then
GetValidateCode=Len(GetValidateCode&9999,4)
End If
End Function
'--------------------------------------------------------
%>
<%ValidateCode=GetValidateCode()'将获取的验证码赋值给ValidateCode%>
<tr bgcolor="#FFFFFF">
<td width="19%" height="25" class="text_12pix_of_20pix"><div align="right">验&nbsp;证&nbsp;码:</div></td>
<td width="81%"><input type="hidden" name="ValidateCode" value="<%=ValidateCode%>"> <input type="text" name="code" value="" size="5" maxlength="4" class="input3"> <%=ValidateCode%> <font color="#ff0000">*</font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="25"><div align="right"></div></td>
<td><input type="submit" name="Submit" value=" 立即发送 "></td>
</tr>
</form>
</table>

<script language="JavaScript" type="text/JavaScript">
<!--
function check(){
name=document.form_mess.name.value;
title=document.form_mess.title.value;
email=document.form_mess.email.value;
content=document.form_mess.content.value;
ValidateCode=document.form_mess.ValidateCode.value;
code=document.form_mess.code.value;

if(email.length!=""&&((email.indexOf('@')==-1)||(email.indexOf('.')==-1)))
{
alert("电子邮件地址填写不正确");
return false;
}

if(title.length=="")
{
alert("请填写主题!");
return false;
}

if(content.length=="")
{
alert("请填写内容!");
return false;
}
if(code.length=="")
{
alert("请填写验证码!");
return false;
}
if(ValidateCode!=code)
{
alert("验证码输入错误!");
return false;
}
return true;
}
//-->
</script>

==============================================================================

send.asp 页

<%
dim sBody
sBody="姓名:"&Request("name")&chr(10)
sBody=sBody&"email:"&Request("email")&chr(10)
sBody=sBody&"电话:"&Request("tel")&chr(10)
sBody=sBody&"其他联系方式:"&Request("other")&chr(10)
sBody=sBody&"标题:"&Request("title")&chr(10)
sBody=sBody&"内容:"&Request("content")&chr(10)

Dim JMail
Set JMail=Server.CreateObject("JMail.SMTPMail")
JMail.Logging=True
JMail.Sender=Request("email")
JMail.Subject="邮件标题"
JMail.Body=sBody
JMail.AddRecipient "mrray@qq.com" '这里是你要发送到的电子邮件地址
JMail.Priority=1
JMail.Execute
Set JMail=nothing
response.write "<script language=javascript>"
response.write "alert('信息提交成功!!');"
response.write "location.replace('message.asp')"
response.write "</script>"
%>

PHP版本

下面这个是关于PHP的

message.php

<script>
<!--
function check(){

company=document.form1.company.value;
lxr=document.form1.lxr.value;
email=document.form1.email.value;
title=document.form1.title.value;
content=document.form1.content.value;
checkNum=document.form1.checkNum.value;

if(company.length=="")
{
alert("请填写客户公司名称!");
return false;
}

if(lxr.length=="")
{
alert("请填写联系人!");
return false;
}

if(email.length=="")
{
alert("请填写电子邮件!");
return false;
}

if(email.length!=""&&((email.indexOf('@')==-1)||(email.indexOf('.')==-1)))
{
alert("电子邮件填写不正确");
return false;
}

if(title.length=="")
{
alert("请填写标题!");
return false;
}

if(content.length=="")
{
alert("请填写内容!");
return false;
}

if(checkNum.length=="")
{
alert("请填写验证码!");
return false;
}

return true;
}
//-->
</script>

<table cellSpacing=1 cellPadding=3 width="80%" border=0>
<form name=form1 action="add_message.php" method=post onsubmit="return check();">

<tr>
<td noWrap align=right width="20%">客户公司名称:</td>
<td width="80%"><font color=#01234a>
<input class=inputl size=30 name="company"> *</font></td>
</tr>
<tr>
<td noWrap align=right width="20%">联系人:</td>
<td width="80%"><font color=#01234a>
<input class=inputl size=10 name="lxr"> *
<input
type=radio CHECKED value=先生 name=sex>
</font>先生
<input type=radio value=小姐 name="sex">
小姐</td>
</tr>
<tr>
<td noWrap align=right width="20%">电子邮件:</td>
<td width="80%"><font color=#01234a>
<input
class=inputl size=25 name=email>
* </font></td>
</tr>
<tr>
<td noWrap align=right width="20%">电话/传真:</td>
<td width="80%"><font color=#01234a>
<input
class=inputl size=25 name=tel>
</font></td>
</tr>
<tr>
<td noWrap align=right width="20%">联系地址:</td>
<td width="80%"><font color=#01234a>
<input
class=inputl size=25 name=addr>
</font></td>
</tr>
<tr>
<td noWrap align=right width="20%">邮编:</td>
<td width="80%"><font color=#01234a>
<input
class=inputl maxLength=6 size=10 name=zip>
</font></td>
</tr>
<tr>
<td vAlign=top noWrap align=right>反馈类别:</td>
<td width="80%"><font color=#818284>
<input
type=radio checked value=业务咨询 name=type1>
业务咨询
<input type=radio value=建议 name=type1>
建议
<input
type=radio value=评价 name=type1>
评价</font></td>
</tr>
<tr>
<td noWrap align=right width="20%">主题:</td>
<td width="80%"><font color=#01234a>
<input class=inputl size=25 name=title> *</font></td>
</tr>
<tr>
<td vAlign=top noWrap align=right
width="20%">内容:</td>
<td width="80%"><TEXTAREA class=inputl name=content rows=5 wrap=VIRTUAL cols=30></TEXTAREA> *</td>
</tr>
<tr>
<td vAlign=top noWrap align=right>&nbsp;</td>
<td><B style="COLOR: #cc6600">
<input class=button1 type=submit value=" 提 交 " name=submit>
<input class=button1 type=reset value=" 重 填 " name=Reset>
</B></td>
</tr>
</form>
</table>

============================================================

add_message.php 页

<?php

$to = "aaa@qq.com";
$to1 = "bbb@126.com";//可以写多个电子邮件地址

$subject = trim($_POST['title']);
$message= "";
$message =$message."反馈类别:".trim($_POST['type1'])."\r\n";
$message = $message."客户公司名称:".trim($_POST['company'])."\r\n";
$message = $message."联系人:".trim($_POST['lxr'])."\r\n";
$message = $message."性别:".trim($_POST['sex'])."\r\n";
$message = $message."电子邮件:".trim($_POST['email'])."\r\n";
$message = $message."电话/传真:".trim($_POST['tel'])."\r\n";
$message = $message."联系地址:".trim($_POST['addr'])."\r\n";

$message = $message."邮编:".trim($_POST['zip'])."\r\n";
$message = $message."内容:".trim($_POST['content'])."\r\n";

mail($to, $subject, $message , "");
mail($to1, $subject, $message , "");

echo "<script>";
echo "window.alert('您的信息提交成功,我们会与您及时联系!');";
echo "location.replace('message.php');";
echo "</script>";
?>

 
 
双击自动滚屏   打印本页 | 关闭窗口

 
 
   
点击这里给我发消息 95616308
点击这里给我发消息 19986151  
 
电话:136-5160-0772   E-mail : Info@YiwebChina.com    
Copyright 2006-2018 © YiwebChian.com   All Rights Reserved