PHP 用mail函数来实现直接提交表单内容到指定邮箱方法
很实用的,但是要服务器邮件支持才行的!
下面这个是关于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> </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>";
?>