我正在重复使用静态网站上的一些代码来填写联系表单。
所以我认为我的问题与wordpress相关。
我已将其他PHP代码留在那里,导致出现问题。
非常感谢任何帮助。
我觉得它可能是表单中的index.php部分。因为现在我的链接必须包含域的扩展名。
www.richardmiddleton.me/growthitude-wordpress是该网站。
提前致谢
PHP
<?php /* Template Name: home */ ?>
<?php
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$from = 'Form on site';
$to = 'Richard@richardemailaddress.me'; // BUSINESS EMAIL ADDRESS
$subject = 'Message from form';
$body ="From: $name\n Number: $phone\n Message:\n $message";
// Check if name has been entered
if (!$_POST['name']) {
$errName = 'Please enter your name';
}
// Check if email has been entered and is valid
if (!$_POST['phone'] || !filter_var($_POST['phone'])) {
$errphone = 'Please enter a valid phone number';
}
//Check if message has been entered
if (!$_POST['message']) {
$errMessage = 'Please enter your message';
}
// If there are no errors, send the email
if (!$errName && !$errPhone && !$errMessage) {
if (mail ($to, $subject, $body, $from)) {
header("Location: success.html");
exit();
} else {
header("Location: fail.html");
exit();
}
}
}
?>
<?php get_header(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php endwhile; ?>
<?php endif; ?>
<?php the_content(); ?>
HTML
<form id="contact-form" role="form" method="post" action="index.php">
<div class="controls">
<div class="row">
<div class="col-md-6">
<!-- Form Name -->
<div class="form-group">
<input type="text" class="form-control" id="name" required="required" name="name" placeholder="NAME (REQUIRED)" value="<?php echo htmlspecialchars($_POST['name']); ?>">
<?php echo "<p class='text-danger'>$errName</p>";?>
<div class="help-block with-errors"></div>
</div>
<!-- END Form Name -->
</div>
<div class="col-md-6">
<!-- Form Number -->
<div class="form-group">
<input type="phone" class="form-control" id="phone" required="required" name="phone" placeholder="PHONE NUMBER (REQUIRED)" value="<?php echo htmlspecialchars($_POST['phone']); ?>">
<?php echo "<p class='text-danger'>$errPhone</p>";?>
<div class="help-block with-errors"></div>
</div>
<!-- END Form Number -->
</div>
</div>
<!-- END ROW 1 FORM -->
<div class="row">
<div class="col-md-12">
<!-- Form Message -->
<div class="form-group">
<textarea class="form-control" rows="10" placeholder="TELL US ABOUT YOUR CLEANING CARE NEEDS" name="message"><?php echo htmlspecialchars($_POST['message']);?></textarea>
<?php echo "<p class='text-danger'>$errMessage</p>";?>
<div class="help-block with-errors"></div>
</div>
<!-- END Form Message -->
</div>
<!-- Form Submit -->
<div class="col-md-12 text-center">
<input id="submit" name="submit" type="submit" value="SEND" class="btn btn-success btn-md">
</div>
<!-- END Form Submit -->
</div>
<!-- Form Required -->
<div class="row">
<div class="col-md-12 text-center">
</div>
<div class="form-group">
<div class="col-sm-12">
<?php echo $result; ?>
</div>
</div>
</div>
</form>
答案 0 :(得分:0)
通常,您需要使用wp_mail()
而不是mail()
功能。第二件事是WordPress有一些已定义的POST信息,你不能使用简单的帖子名称字段。
您有姓名,电子邮件,消息,提交等名称。
你无法使用它。。
将其替换为bzx_name
,bzx_email
,bzx_message
等前缀,并在POST替换为$_POST['bzx_name']
。
如果您只是刷新页面,请从index.php
内的action
属性中删除form
,如果您需要再使用其他网址,请提供完整的网址。
修复后这将正常工作。