大家好,我的联系表格已经准备好了html和php(2个不同的文件,一个html和一个php文件),我想在worpress页面中使用它。 用户填写表格,选择支持部门回答验证码并按下提交按钮。表单通过电子邮件将所有表单数据发送给管理员,感谢用户发送电子邮件并重定向到感谢页面。 html表单是
<html>
<body>
<head>
<script src="http://www.google.com/recaptcha/api.js" async defer> </script>
<script type="text/javascript" src="http://www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script>
</head>
<i>Use the form to get in touch with us.</i>
<form action="form.php" method="POST">
<strong>Name:*</strong>
<input style="width:300px;" name="username" type="text" required />
<strong>E-mail Adress:*</strong>
<input style="width:300px;" name="useremail" type="text" required />
<strong>Subject:*</strong>
<input style="width:300px;" name="usersubject" type="text" required />
<strong>Message:*</strong>
<textarea style="width:300px;" cols="40" name="usermessage" rows="5" required></textarea>
<strong>Select Support Department </strong>
<select name="support">
<option style="width:200px;" value="" >Choose Service</option>
<option style="width:200px;" value="support@xxxxxxxx.com" required>Technical support</option>
<option style="width:200px;" value="sales@xxxxxxxxxx.com" required>Sales</option>
<option style="width:200px;" value="info@xxxxxxxxxxx.com" required>Press</option>
<option style="width:200px;" value="info@xxxxxxxxxxx.com" required>Other</option>
</select>
//recaptcha
<div class="g-recaptcha" data- sitekey="------my site key---------"></div>
<input type="submit" value="send" name="submit"/>
//it redirects when you hit submit
<?php
if ( isset( $_POST['submit'] ) ){
header("Location:http://xxxxxxxxx.com/thank-you-messasge/");
}
?>
</form>
</html>
</body>
我的form.php是
<?
//set up the message for administrator
$msg="Name:".$_POST["username"]."\n";
$msg .="E-mail:".$_POST["useremail"]."\n";
$msg .="Subject:".$_POST["usersubject"]."\n";
$msg .="Usermessage:".$_POST["usermessage"]."\n";
//set up message for customer
$msg_customer="We received your request and we will answer you within 24 hours.";
$msg_customer.="\n"."xxxxxxxxxxxxxx";
//set up the email for the administrator
$recipient=$_POST["support"];
$subject= "Support Contact Form ";
$mailheaders="From: xxxxxxxx sales@xxxxxxxxx.com \n";
//set up the email for the customer
$recipient_customer=$_POST["useremail"];
$subject_customer= "Support Contact Form ";
$mailheaders_customer="From: xxxxxxxxxx sales@xxxxxxxxxxxxxxx.com \n";
//send the emails
mail($recipient,$subject,$msg, $mailheaders);
mail($recipient_customer,$subject_customer,$msg_customer, $mailheaders_customer);
?>
我希望这个表单出现在一个页面中,并且能够在按下提交按钮时运行php代码。 即使我将它保存在根目录中,我也无法运行form.php文件。 好像我在失去一些东西 非常感谢你
答案 0 :(得分:0)
要对表单进行问题排查,请在浏览器中按F12以访问开发人员工具菜单,并在提交表单时查看“网络”面板上发生的情况。这应该会为你提供一些关于失败的线索。
此外,您不应直接使用未经过滤的$_POST
变量,例如:
$name = sprintf("Name:%s\n", filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING) );
答案 1 :(得分:-1)
<form action="http://example.com/php_file_directory/form.php" method="POST">