简体   繁体   English

WordPress的联系表格不起作用-可能是由于functions.php中的代码

[英]Wordpress Contact Form does not work - probably due to code in functions.php

Below is the code to my wordpress contact form, probably there is some mistake because when I enter my page url http://muzykablog.pl/ the url jumps automatically to http://muzykablog.pl/page-kontakt.php?msg_sent=true ... 下面是我的wordpress联系表的代码,可能有一些错误,因为当我输入页面网址http://muzykablog.pl/时,该网址会自动跳转到http://muzykablog.pl/page-kontakt.php?msg_sent =真 ...

This is the code inside my contact page (page-kontakt.php) : 这是我的联系页面(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="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) : 这是我的函数页面(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');
}

There has to be some mistake here 这里一定有错误

It could be better to see the mail() function. 最好查看mail()函数。 But seeing the code it seems it will always return true or false so it will redirect to ?msg_sent=false or ?msg_sent=true. 但是看到代码后,它似乎总是会返回true或false,因此它将重定向到?msg_sent = false或?msg_sent = true。 For some reason your page is always sending the form when loads. 由于某些原因,页面在加载时总是发送表单。 You must avoid that. 您必须避免这种情况。 Its rare too that the action of the form is functions.php. 表单的动作是functions.php也是很少见的。 Are you trying to put the form in the home page? 您是否要在主页上放置表格?

I think there are more deep problems but it could be arranged (not very pro) with this in your functions.php 我认为还有更多更深层次的问题,但是可以在您的functions.php中进行安排(不是很专业)

if($_POST['human']!=""){

$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');
} 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM