我正在为建筑物入口的网页上创建4个按钮。我使用"很棒的菜单"作为页面布局,就像演示一样http://line25.com/wp-content/uploads/2009/css-menu/demo/demo.html
因此,点击每个菜单按钮,就会自动向相应的部门发送一封电子邮件。例如,点击忍者按钮,发送一封电子邮件到ninja@example.com
我有我的php表单,我想用它来发送电子邮件,我的问题是如何将我的php表格与这个菜单列表代码结合起来?我有点迷路了,所以任何帮助都很感激。
这是我的页面布局代码,使用css将图像附加到每个按钮上,就像很棒的菜单演示下载代码一样。
<body>
<ul id="awesome-menu">
<li><a href="#ninja" class="ninja">Ninja</a></li>
<li><a href="#zombie" class="zombie">Zombie</a></li>
</ul>
</body>
这是我想用来发送电子邮件的php表单代码
<form action="" method="post"> //for first list
<input type="submit" value="Send details" />
<input type="hidden" name="button_a" value="1" />
</form>
<?php
if(isset($_POST['button_a']))
{
$to = 'ninja@example.com';
$subject = 'You have a visitor';
$message = 'hello I am here to see ninja';
$headers = 'From: webmaster@site.com' . "rn" .
'Reply-To: webmaster@site.com' . "rn" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
echo 'Email Sent A.';
}
?>
//for second list
<form action="" method="post">
<input type="submit" value="Send details to b" />
<input type="hidden" name="button_b" value="1" />
</form>
<?php
if(isset($_POST['button_b']))
{
$to = 'zombie@example.com';
$subject = 'You have a visitor';
$message = 'hello I am here to see zombie';
$headers = 'From: webmaster@site.com' . "rn" .
'Reply-To: webmaster@site.com' . "rn" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
echo 'Email Sent.';
}
?>
你可以试试这样的东西:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<ul id="awesome-menu">
<li>
<form action="emailAndRedirect.php" id="ninja" method="post">
<input type="hidden" name="name" value="ninja" />
</form>
<a href="javascript:void" onclick="formSubmit('ninja')" class="ninja">Ninja</a>
</li>
<li>
<form action="emailAndRedirect.php" id="ninja" method="post">
<input type="hidden" name="name" value="zombie" />
</form>
<a href="javascript:void" onclick="formSubmit('zombie')" class="zombie">Zombie</a>
</li>
</ul>
<script type="text/javascript">
function formSubmit(name)
{
if (name == 'ninja') {
document.getElementById("ninja").submit();
} else if (name == 'zombie') {
document.getElementById("zombie").submit();
}
}
</script>
</body>
</html>
在您的php:中
<?php
$url = //url of the page you wan t
if (isset($_POST['name'])) {
$name = $_POST['name'];
if ($name == 'ninja') {
$email = 'ninja@example.com';
} else if ($name == 'zombie') {
$email = 'zombie@example.com';
}
}
$to = $email;
$subject = 'You have a visitor';
$message = 'hello I am here to see $name';
$headers = 'From: webmaster@site.com' . "rn" .
'Reply-To: webmaster@site.com' . "rn" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
header('Location: $url#$name');
?>
编辑:Thjs使用javascript,所以你会依赖它。使用javascript表单提交功能,你可以保持相同的链接和样式,并且仍然提交表单。