我正在网页上为建筑物入口创建 4 个按钮。我正在使用“awesome menu”作为页面布局,就像演示一样 http://line25.com/wp-content/uploads/2009/css-menu/demo/demo.html
因此,单击每个菜单按钮后,系统会自动将电子邮件发送到相应的部门。例如,单击 Ninja 按钮,将向 ninja@example.com 发送一封电子邮件
我有我的 php 表单,我想用它来发送电子邮件,我的问题是如何将我的 php 表单与这个菜单列表代码结合起来?我有点迷路,所以感谢您的帮助。
这是我的页面布局代码,使用 css 将图像附加到每个按钮,如 awesome menu演示下载代码。
<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' . "\r\n" .
'Reply-To: webmaster@site.com' . "\r\n" .
'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' . "\r\n" .
'Reply-To: webmaster@site.com' . "\r\n" .
'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' . "\r\n" .
'Reply-To: webmaster@site.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
header('Location: $url#$name');
?>
编辑:Thjs 使用 javascript,所以你会依赖它。使用 javascript 表单提交功能,您将能够保留相同的链接和样式并仍然提交表单。
关于php - 如何将 php 发送邮件表单与图像点击列表结合起来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9386425/