我正在使用wordpress安装在XAMPP上开发。
我的表单看起来不错,一切都是我想要的但是当我点击提交按钮时它会加载而index.php也就是我的网站主页。
所以当我点击提交时,它来自
到
http://localhost/WP/contact/index.php
虽然没有任何信息,但它不应该工作......我试着按照教程,所以我只是迷失了,而且我还在学习JS和PHP的基础知识。
这是我的表格代码
<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: $email';
$to = 'alexgray410@gmail.com';
$subject = 'Hello';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
}
?>
<header class="body">
</header>
<section class="body">
<form method="post" action="index.php" class="contact">
<label class="contact">Name</label>
<input name="name" placeholder="Type Here" class="contact">
<label class="contact">Email</label>
<input name="email" type="email" placeholder="Type Here" class="contact">
<label class="contact">Message</label>
<textarea name="message" placeholder="Type Here" class="contact"></textarea>
<label class="contact">*What is 2+2? (Anti-spam)</label>
<input name="human" placeholder="Type Here" class="contact">
<input id="submit" name="submit" type="submit" value="Submit" class="contact">
</form>
</section>
<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: TangledDemo';
$to = 'demo@tangledindesign.com';
$subject = 'Hello';
$human = $_POST['human'];
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit']) {
if ($name != '' && $email != '') {
if ($human == '4') {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
} else {
echo '<p>You need to fill in all required fields!!</p>';
}
}
}
?>
答案 0 :(得分:0)
您尚未添加标题,请参阅下面正确的php邮件格式。
$to=$to_email;
$subject ="Your subject";
$website="example.com";
// Set headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$website.'<'.$sender_email. ">\r\n";
// Format message
$contactMessage =
"Your message";
// Send email
$mail_sent=mail($to, $subject, $contactMessage, $headers);
答案 1 :(得分:0)
我认为网站是在WordPress中
在php {/ p>的if(isset($_POST['submit'])){}
地方标题重定向结束时
<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: TangledDemo';
$to = 'demo@tangledindesign.com';
$subject = 'Hello';
$human = $_POST['human'];
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit']) {
if ($name != '' && $email != '') {
if ($human == '4') {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
} else {
echo '<p>You need to fill in all required fields!!</p>';
}
}
}
header("location:".get_the=permalink(<page_ID_of_CONTACT US page>));
?>
}
header()函数应该是关闭if条件
之前的所有内容