分類
程序 网站

用php处理表单的数据

下面代码在接收到数据后先将数据储存与数据库,再将数据以电子邮件方式通知自己。

<?php
$author=$_POST["name"];$email=$_POST["email"];$title=$_POST["subject"];$message=$_POST["message"];
$con=mysql_connect("数据库地址","数据库用户名","数据库密码");
if(!$con){
	die('Could not connect: '.mysql_error());
	}
mysql_query("set names utf8");
mysql_select_db("数据库名",$con);
mysql_query("INSERT INTO `数据表名` (`id`, `date`, `author`, `email`, `title`, `message`) VALUES (NULL, CURRENT_TIMESTAMP, '$author', '$email', '$title', '$message')");
mysql_close($con);
$myNotify = "Name:$authornEmail:$emailnTitle:$titlenMessage:$message";
$myNotify = wordwrap($myNotify,70);
mail("自己的邮箱@gmail.com","your tittle",$myNotify,'From:发送自@ft.wupo.info');//邮件标题如果有中文要进行编码,否则会乱码,故这里没有使用$title
echo ""; 
exit;
?>

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *