Php 联系方式不起作用
当我提交表格时,我得到了404页。有些东西不见了,或是出了问题。 这是一个wordpress网站。我在wordpress的选项中插入了电子邮件,但什么也没发生。我看到了很多堆栈溢出问题,但没有一个对我有帮助。我不想使用插件Php 联系方式不起作用,php,wordpress,Php,Wordpress,当我提交表格时,我得到了404页。有些东西不见了,或是出了问题。 这是一个wordpress网站。我在wordpress的选项中插入了电子邮件,但什么也没发生。我看到了很多堆栈溢出问题,但没有一个对我有帮助。我不想使用插件 <form class="form-horizontal" role="form" method="post" action="contact.php"> <div class="input-group">
<form class="form-horizontal" role="form" method="post" action="contact.php">
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-user"></i></span>
<input type="text" class="form-control" id="name" name="name" placeholder="Name" value="">
</div>
<br/>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-envelope"></i></span>
<input type="email" class="form-control" id="email" name="email" placeholder="example@domain.com" value="">
</div>
<br/>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-pencil"></i></span>
<textarea class="form-control" rows="4" name="message" placeholder="Message..."></textarea>
</div>
<br/>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">2 + 3 = ?</span>
<input type="text" class="form-control" id="human" name="human" placeholder="">
</div>
<br/>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-5">
<input id="submit" name="submit" type="submit" value="Enviar" class="btn btn-button">
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<! Will be used to display an alert to the user>
</div>
</div>
</form>
PHP代码:
在当前主题中创建一个.php文件,如果有子主题,则在thild主题中创建一个.php文件,然后将下面的代码放入该文件并保存它
<?php
/*
* Template Name: Contact us
*/
get_header();
if (isset($_POST["submit"]))
{
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$human = intval($_POST['human']);
$from = 'Contact Form';
$to = 'example@domain.com';
$subject = 'Contact ';
$body = "From: $name\n E-Mail: $email\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['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
{
$errEmail = 'Please enter a valid email address';
}
//Check if message has been entered
if (!$_POST['message'])
{
$errMessage = 'Please enter your message';
}
//Check if simple anti-bot test is correct
if ($human !== 5)
{
$errHuman = 'Your anti-spam is incorrect';
}
// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage && !$errHuman)
{
if (mail ($to, $subject, $body, $from))
{
$result='<div class="alert alert-success">Thank You! I will be in touch</div>';
}
else
{
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
}
}
}
?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<form class="form-horizontal" role="form" method="post" action="#">
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-user"></i></span>
<input type="text" class="form-control" id="name" name="name" placeholder="Name" value="">
</div><br/>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-envelope"></i></span>
<input type="email" class="form-control" id="email" name="email" placeholder="example@domain.com" value="">
</div><br/>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-pencil"></i></span>
<textarea class="form-control" rows="4" name="message" placeholder="Message..."></textarea>
</div><br/>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">2 + 3 = ?</span>
<input type="text" class="form-control" id="human" name="human" placeholder="">
</div><br/>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-5">
<input id="submit" name="submit" type="submit" value="Enviar" class="btn btn-button">
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<!-- Will be used to display an alert to the user -->
</div>
</div>
</form>
</main>
<?php get_sidebar( 'content-bottom' ); ?>
</div>
<?php get_footer(); ?>
现在转到wp管理员并创建新页面标题可能是contact page等,从页面内容右侧的页面模板下拉列表中选择页面模板contact us,发布页面并查看页面。
希望能有所帮助。在实际操作中使用文件位置url:
action="`<?php echo get_template_directory()'contact.php';?>`"
试试这个 首先感谢您的回复 这里的问题是php邮件。我希望我能在这方面帮助别人 为了得出这一结论,采取了以下步骤: 尝试了我在stack overflow中看到的所有问题,同样的问题困扰着我; 安装 我没有收到任何电子邮件,所以我联系了我的托管服务,他们说他们不会让php邮件避免垃圾邮件。
-发生这种情况时,这是最好的解决方法。那么contact.php不存在,它在同一个文件夹中。但我猜这张表格找不到他。你知道为什么吗?情况正确吗?contact.php!=*NIX systems上的Contact.php我正在回答您删除的答案。谢谢你的回复。我问我什么时候需要,在其他的stackoverflow页面中,我有一些名声,没什么大不了的。如果我得到一个好答案,我可以投反对票。我在询问之前搜索了contact.php,但正如我在评论中所说的,可能表单无法获取文件,我尝试了很多方法,但我无法解决这个问题。这个方法也不管用啊它的wordpress我想你需要这样的东西才能让它工作@APDP你试过了吗?嗨,很抱歉耽搁了,谢谢你的回复。那没用。这种错误从未发生在我身上。始终是404页。您的永久链接设置是什么?另外,请尝试从上面的代码中删除action=。不,如果您阅读了我上面的评论,您可以看到我尝试了。解析错误:语法错误。没有php,我就得到了404。谢谢您的回复。请尝试此功能。再次感谢您的回复,但请再次尝试404。如果你阅读了这些评论,你会发现有些人甚至在代码中也有同样的问题。
action="`<?php echo get_template_directory()'contact.php';?>`"