电子邮件表单missing_content消息未显示

时间:2018-01-27 11:15:01

标签: php email

解决

我收到了一个404页面的电子邮件表格,也可以在出现错误或邮件发送时显示一条消息。 该脚本工作正常,直到最近的更新强迫我在很多行上使用isset()来摆脱一些错误。

接受有一条我无法显示的消息;当两个字段都为空时,显示的missing_content消息。代码:

    <?php
    $response = "";

    function my_contact_form_generate_response($type, $message){
        global $response;
        if($type == "success") $response = "<p><div class='success' style='margin-right: 10vw;'>{$message}</div></p>";
        else $response = "<p><div class='error' style='margin-right: 10vw;'>{$message}</div></p>";
    }
    $not_human          = "Are you sure you're not a robot?";
    $missing_content    = "Please fill in every field.";
    $message_unsent     = "Something went wrong, please try again.";
    $message_sent       = "Thanks for your help, your message has been send.";
    $name       = wp_get_current_user();

    if (isset($_POST['message_text'])) {
        $message    = $_POST['message_text'];
    }
    if (isset($_POST['message_human'])) {
        $human      = $_POST['message_human'];
    }
    $to = "fake@mail.com";
    $subject = "404 found by: " . $name->user_login;

    if (isset($human)) {
        if(!$human == 0){
            if($human != $_SESSION['outcome']) {
                my_contact_form_generate_response("error", $not_human);
            } else {
                if(empty($message)){
                    my_contact_form_generate_response("error", $missing_content);
                } else {
                    $message = "link: http://vespa-ciao.nl" . $url . "\n\n" . $message;
                    $sent = wp_mail($to, $subject, strip_tags($message));
                    if($sent) my_contact_form_generate_response("success", $message_sent);
                    else my_contact_form_generate_response("error", $message_unsent);
                    // I was unable to test the message_unsent repons so I asume it works
                }
            }
        }
    } else if (isset($_POST['submitted'])) { 
        my_contact_form_generate_response("error", $missing_content);
        // This is the message that is not displayed
    }
    $number = array( mt_rand(1,5), mt_rand(6,10) );
    $outcome = $number[1] - $number[0];
    $_SESSION['outcome'] = $outcome;
    ?>

这几乎是脚本底部的部分对我不起作用。我在没有isset()的情况下尝试过,尝试使用$_SESSION,将其置于顶部,丢失了else语句,我甚至不记得我尝试过的所有其他内容但它不会显示。

非常感谢一些帮助。

1 个答案:

答案 0 :(得分:0)

通过改变来实现它:

    @Test
    fun fromStringJsonToObject4() {
        val gsonHelper = GsonHelper()
        val payloadJsonString = "{}"
        val payload = Payload("", 0, 0, 0)

        assertEquals(gsonHelper.fromStringJsonToObject(payloadJsonString, Payload::class.java), payload)
    }

进入这个:

Expected :Payload(uniqueName=null, nbf=0, exp=0, iat=0)
Actual   :Payload(uniqueName=, nbf=0, exp=0, iat=0)

不再需要帮助