[英]Wordpress contact form won't work
所以这是我第一次使用wordpress,所以我的知识相对较少,但是我已经用html和css制作并设置了联系表单,我正在尝试激活表单,以便将数据发送到我的电子邮件,但是无论我什么都不做似乎有效。
这是我目前正在使用的代码
<?php
/* template name: contact Page*/
?>
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: TangledDemo';
$to = 'kazumajshimizu@gmail.com';
$subject = 'Hello';
?>
<?php get_header(); ?>
<div id='main-content'>
<div id="page_title" class=" animated fadeIn delay1 duration2" >
<h1>CONTACT</h1>
<br>
<p> I would love to hear fom you, so please feel free to get in touch and contact me for any enquires or further information. </p>
<div class="fade_line"></div>
</div>
<div class="main_about">
<div id="wrapper_two">
<div id="left_one" class="animated fadeInDown delay3 duration2">
<form action="page_contact.php" method="post" class="contact_form" >
<label for="Name">
<input id="name" type="text" name="name" placeholder="NAME" />
</label>
<label for="Email">
<input id="email" type="email" name="email" placeholder="EMAIL" />
</label>
<label for="message">
<textarea id="message" name="message" placeholder="MESSAGE"></textarea>
</label>
<button name="submit" type="submit" class="button_send" value="send">SEND</button>
</form>
</div>
<div id="right_one" class="animated fadeInDown delay3 duration2">
<div id="map"></div>
<br>
<br>
<br>
<h3> Adress </h3>
<p>7 Silvabank CRT, Warner, 4500, Qld, Australia</p>
<br>
<h3>Phone</h3>
<p>0403144971</p>
<br>
<h3> Email </h3>
<p>kazumajshimizu@gmail.com</p>
</div>
</div>
<div id="insta" class="animated fadeInDown delay3 duration2">
<h3>INSTAGRAM</h3>
<div class="fade_line"></div>
<?php echo do_shortcode('[instagram-feed]'); ?>
</div>
</div>
<?php get_footer(); ?>
</div>
<script src="https://maps.googleapis.com/maps/api/js"></script>
<script>
function initialize() {
var mapCanvas = document.getElementById('map');
var mapOptions = {
center: new google.maps.LatLng(-27.4667, 153.0333),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(mapCanvas, mapOptions)
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
我也尝试过
<?php
/* template name: contact Page*/
?>
<?php
//response generation function
$response = "";
//function to generate response
function generate_response($type, $message){
global $response;
if($type == "success") $response = "<div class='success'>{$message}</div>";
else $response = "<div class='error'>{$message}</div>";
}
//response messages
$not_human = "Human verification incorrect.";
$missing_content = "Please supply all information.";
$email_invalid = "Email Address Invalid.";
$message_unsent = "Message was not sent. Try Again.";
$message_sent = "Thanks! Your message has been sent.";
//user posted variables
$name = $_POST['message_name'];
$email = $_POST['message_email'];
$message = $_POST['message_text'];
$human = $_POST['message_human'];
//php mailer variables
$to = get_option('admin_email');
$subject = "Someone sent a message from ".get_bloginfo('name');
$headers = 'From: '. $email . "\r\n" .
'Reply-To: ' . $email . "\r\n";
if(!$human == 0){
if($human != 2) generate_response("error", $not_human); //not human!
else {
//validate email
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
generate_response("error", $email_invalid);
else //email is valid
{
//validate presence of name and message
if(empty($name) || empty($message)){
generate_response("error", $missing_content);
}
else //ready to go!
{
$sent = mail($to, $subject, $message, $headers);
if($sent) generate_response("success", $message_sent); //message sent!
else generate_response("error", $message_unsent); //message wasn't sent
}
}
}
}
else if ($_POST['submitted']) generate_response("error", $missing_content);
?>
<?php get_header(); ?>
<style type="text/css">
.error{
padding: 5px 9px;
border: 1px solid red;
color: red;
border-radius: 3px;
}
.success{
padding: 5px 9px;
border: 1px solid green;
color: green;
border-radius: 3px;
}
form span{
color: red;
}
</style>
<div id='main-content'>
<div id="page_title" class=" animated fadeIn delay1 duration2" >
<h1>CONTACT</h1>
<br>
<p> I would love to hear fom you, so please feel free to get in touch and contact me for any enquires or further information. </p>
<div class="fade_line"></div>
</div>
<div class="main_about">
<div id="wrapper_two">
<div id="left_one" class="animated fadeInDown delay3 duration2">
<div id="respond">
<?php echo $response; ?> </div>
<form class="contact_form"action="<?php the_permalink(); ?>" method="post" >
<label for="Name">
<input type="text" name="message_name" placeholder="NAME" value="<?php echo $_POST['message_name']; ?>">
</label>
<label for="Email">
<input type="text" name="message_email" placeholder="EMAIL" value="<?php echo $_POST['message_email']; ?>">
</label>
<label for="message">
<textarea id="message" name="message_human" placeholder="MESSAGE"></textarea>
</label>
<button id="submit" name="submit" type="submit" class="button_send" value="send">SEND</button>
</form>
</div>
<div id="right_one" class="animated fadeInDown delay3 duration2">
<div id="map"></div>
<br>
<br>
<br>
<h3> Adress </h3>
<p>7 Silvabank CRT, Warner, 4500, Qld, Australia</p>
<br>
<h3>Phone</h3>
<p>0403144971</p>
<br>
<h3> Email </h3>
<p>kazumajshimizu@gmail.com</p>
</div>
</div>
</div>
<div id="insta" class="animated fadeInDown delay3 duration2">
<h3>INSTAGRAM</h3>
<div class="fade_line"></div>
<?php echo do_shortcode('[instagram-feed]'); ?>
</div>
</div>
<?php get_footer(); ?>
</div>
<script src="https://maps.googleapis.com/maps/api/js"></script>
<script>
function initialize() {
var mapCanvas = document.getElementById('map');
var mapOptions = {
center: new google.maps.LatLng(-27.4667, 153.0333),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(mapCanvas, mapOptions)
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
似乎都不起作用。 任何人都可以给我任何帮助,我将不胜感激,因为我已经花了数小时试图解决这个问题。 这是我网站的链接http://shimizudesigns.com/contact/
名称为“ name”的输入字段会导致该情况。 将其更改为“用户名”之类的名称,它应该开始工作。 我有类似的问题。 如果您想查看源代码,请参阅我的类似问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.