douhuan6065 2015-09-05 12:27
浏览 66

Wordpress联系表格不起作用

THe code below does not work. This is the code inside my contact page (page-kontakt.php) :

<h4>Send Us Mail</h4><br/>


    <?php
if ($_GET[msg_sent]=='true' ) {
    echo '<div>Your message has been sent!</div>';
}elseif ($_GET[msg_sent]=='false') {
    echo '<div>An error occurred sending your message.</div>';
}else{
?>           

             <form method="post" action="<?php echo LEARNINGWORDPRESS_THEME_URL ?>functions.php">
            <label>Name</label>
            <input name="name" placeholder="Type Here">

            <label>Email</label>
            <input name="email" type="email" placeholder="Type Here">

            <label>Message</label>
            <textarea name="message" placeholder="Type Here"></textarea>

            <label>*What is 2+2? (Anti-spam)</label>
            <input name="human" placeholder="Type Here">

            <input id="submit" name="submit" type="submit" value="Submit">

        </form>

        <?php } ?>

This is the code inside my functions page (functions.php) :

// KONTAKT - MESSAGE SENDING FUNCTIONS FOR page-kontakt.php


    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $from = 'From: http://muzykablog.pl/'; 
    $to = 'piterdeja@gmail.com'; 
    $subject = 'Hello';
    $human = $_POST['human'];

    $body = "From: $name
 E-Mail: $email
 Message:
 $message";

    if(mail($to, $subject, $body, $from)){
    header('Location:page-kontakt.php?msg_sent=true');
}else{
    header('Location:page-kontakt.php?msg_sent=false');
}

In my wordpress site I want to be able to enter muzykablog.pl/kontakt where my contact form is (right now url muzykablog.pl/kontakt does not work) and after filling all the input windows like 'email' 'message' and clicking 'submit' I want to receive email message to the email address which I specified. Notice that I specified absolute path:

             <form method="post" action="<?php echo LEARNINGWORDPRESS_THEME_URL ?>functions.php">

Maybe it is necessary to specify absolute path in

Location:page-kontakt.php?msg_sent=true

...as well, but how to specify absolute path in functions.php ?

  • 写回答

2条回答 默认 最新

  • dpvhv66448 2015-09-05 12:54
    关注
    You should change the code like this. Change the form action to blank
    
     <form method="post" action="">
                <label>Name</label>
                <input name="name" placeholder="Type Here">
    
                <label>Email</label>
                <input name="email" type="email" placeholder="Type Here">
    
                <label>Message</label>
                <textarea name="message" placeholder="Type Here"></textarea>
    
                <label>*What is 2+2? (Anti-spam)</label>
                <input name="human" placeholder="Type Here">
    
                <input id="submit" name="contactSubmit" type="submit" value="Submit">
    
            </form>
    
    in functions.php you need to do the following code.
    
    add_action('init','contact_submit');
    
    function contact_submit(){
    //contactSubmit is name of submit input field
      if($_POST['contactSubmit']){
        you submit code will be here
      }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?