duankun9280 2015-12-26 13:07
浏览 10

联系表格,这会有用吗? 我正在使用wordpress模板

So, i've created a php webpage for wordpress (just new into this). My question is because I couldn't find any wordpress plugins to do this better for my custom layout. I wanted to create a contact form on my own and I tried my best to create this script but I don't think it works, I do not recieve any email in my mailbox. Is it because i'm on localhost? Or is the problem in the script?

<?php
/*
Template Name: Contact Page Layout.
*/
get_header();
?>
<div id="content" style="padding-top: 8em; background: none;">
<?php
if (have_posts()):
  while (have_posts()):
    the_post();
?>
<div id="contacttable">
<ul>
    <li class="google-maps block" id="first-block">
    <?php echo do_shortcode('[wpgmza id="1"]');?>
    </li>
    <li class="info block" id="second-block">
    <?php  the_content(); ?> 
    </li>
    <li class="quote block" id="third-block">
    <h3> <?php  the_title(); ?> </h3>
    </li>
    <li class="message block" id="forth-block">
    <?php
    $action = $_REQUEST['POST'];
    if ($action == "") /* display the contact form */ {   ?>
    <form  action="" method="POST" enctype="multipart/form-data">
    <textarea name="message" rows="7" cols="30" id="myTextarea"></textarea><br>
    <input type="submit" id="submit" value="Send."/>
    </form>
    </li>
    <li class="picture block" id="fifth-block">
    <img src="wp-content/themes/gcustom/img/contact_img.png" height="100%" style="maxwidth: 100%;">
    </li>
    <li class="email block" id="sixth-block">
    <input name="email" type="text" value="" size="30" id="email"/><br>
    <?php
    } else {
      $email   = $_REQUEST['email'];
      $message = $_REQUEST['message'];
      if (($email == "") || ($message == "")) {
        alert("All fields are required, please fill <a href=\"\">the form</a> again.");
        $message = "not sended";
        echo "<script type='text/javascript'>alert('$message');</script>";
      } else {
        $message = "sended";
        echo "<script type='text/javascript'>alert('$message');</script>";
        $admin_email = get_option('admin_email');
        $from        = "From: <$email>
Return-path: $email";
        $subject     = "Message from your G-CUSTOM contact-form!";
        mail($admin_email, $subject, $message, $from);
        echo "Email sent!";
      }
    }
?> 
  </li>
  </ul>
  </div>

  <?php
  endwhile;
endif;
?>
</div>
<script type="text/javascript">
    document.getElementById("myTextarea").value = "Hello,";
    document.getElementById("email").value = "Enter your email.";
</script>
<?php    get_footer();    ?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了