Wordpress联系表单不起作用

时间:2015-09-05 12:27:56

标签: php wordpress

以下代码不起作用。这是我的联系页面内的代码(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 } ?>

这是我的函数页面(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\n E-Mail: $email\n Message:\n $message";

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

在我的wordpress网站上,我希望能够输入muzykablog.pl/kontakt我的联系表格(现在url muzykablog.pl/kontakt不起作用),并填写所有输入窗口,如'email''消息'并点击'提交'我想收到我指定的电子邮件地址的电子邮件。请注意,我指定了绝对路径:

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

可能需要在

中指定绝对路径
Location:page-kontakt.php?msg_sent=true

......同样,但是如何在functions.php中指定绝对路径?

2 个答案:

答案 0 :(得分:0)

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
  }
}

答案 1 :(得分:0)

由于您使用wordpress,为什么不使用一些预制解决方案,例如联系表单7.您只需从存储库中获取插件并使用短代码插入页面。如果需要,你甚至可以设计它