第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

ajax jquery 表單停止發(fā)送電子郵件

ajax jquery 表單停止發(fā)送電子郵件

PHP
慕沐林林 2022-10-14 10:46:11
我有一個(gè)表單,它之前從服務(wù)器發(fā)送電子郵件,但突然停止工作。我似乎無(wú)法弄清楚這個(gè)問(wèn)題。當(dāng)我使用沒(méi)有 ajax 的表單時(shí),電子郵件可以完美運(yùn)行。我在開(kāi)發(fā)工具中看到了 http 200 代碼,沒(méi)有錯(cuò)誤。任何幫助將非常感激。謝謝你。html:<form id="form1" class="form-action" action="" method="POST">        <input type="text" name="name" id="name" class = "name" required />        <input type="email" name="email" id="email"  required />        <input type="text" name='company' id="company" class="company" required />        <textarea class= "message" name="message" id="message" required />         </textarea><script src="https://www.google.com/recaptcha/api.js"></script><div class="g-recaptcha" data-sitekey="x" data-callback="recaptcha"></div>     <button type="submit" id="submit-button">Submit</button>     <span class="success_message font-weight-bolder text-center hide" style="margin-left: 30px;">                                            message received.</span></form><script>function reset_form(){        $("#form1")[0].reset();    }    function reset_success_message(){        $('.success_message').addClass('hide');    }    $(document).ready(function(){        $('#name').click(function () {            $('.success_message').addClass('hide');        });        $('.email').click(function () {            $('.success_message').addClass('hide');        });        $('.company').click(function () {            $('.success_message').addClass('hide');        });        $('#message').click(function () {            $('.success_message').addClass('hide');        });        $('#form1').submit(function (e) {            $('.success_message').addClass('hide');            e.preventDefault();            $.ajax({               url: 'serverside.php',               type: 'post',               data: $('#form1').serialize(),               success: function (response) {                    if(response == 'submitted'){                        reset_form();                        $('.success_message').removeClass('hide');                    }               }            });        });    });</script>
查看完整描述

1 回答

?
鴻蒙傳說(shuō)

TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊

你似乎錯(cuò)過(guò)了 Recaptcha 的秘密。如果條件正常,則刪除 Recaptcha。

http://img1.sycdn.imooc.com//6348cd9e0001462a09890378.jpg

<?php


    $email_to = 'ahmed_rises@hotmail.com'; //-----------> Invalid Email Id was added here

    $email_subject = 'form submission';

    $email = $_POST ['email'];


    $required = array('name','email','company', 'message');



    $form1_complete = FALSE;


    $validation = array();


    if(!empty($_POST)) {


        foreach($_POST as $key => $value) $_POST[$key] = remove_email_injection(trim($value));


        foreach($required as $field) {


            if(!array_key_exists($field, $_POST)) array_push($validation, $field);


            if($_POST[$field] == '') array_push($validation, $field);


            if($field == 'email') if(!validate_email_address($_POST[$field])) array_push($validation, $field);

        }


        if(count($validation) == 0) {

            $email_content = 'New Comment: ' . "\n\n";


            foreach($_POST as $key => $value) {

                if($key != 'submit') $email_content .= $key . ': ' . $value . "\n\n ";

            }


            //Recaptca Secrets are Missing?????? Random string passed!

            $recaptcha_secret = "x";


            $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret="

            .$recaptcha_secret."&response=".$_POST['g-recaptcha-response']); //-----> Also Recapta response from

            //the form is also missing since there its not working and neither getting passed


            $response = json_decode($response, true);


            //Printed the Output in which it shows the recapta Error

            echo "<pre>";

            print_r($response);


            //If you ae to remove the Recapta Condition, the mail will be send!

            // if($response["success"] === true) {

                echo "==========";


                echo "email_subject:".$email_subject.", email:".$email.",email_to:".$email_to;

                mail($email_to, $email_subject, $email_content, "From:" . $email);


                echo "==========";


            // }

            // else

            // {

            //     echo "Failed";

            // }


            echo "<br>";

            echo 'submitted';

        }

    }


    function validate_email_address($email = FALSE) {

        return (preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i', $email))? TRUE : FALSE;

    }


    function remove_email_injection($field = FALSE) {

        return (str_ireplace(array("\r", "\n", "%0a", "%0d", "Content-Type:", "bcc:","to:","cc:"), '', $field));

    }


?>

希望能幫助到你 :)


查看完整回答
反對(duì) 回復(fù) 2022-10-14
  • 1 回答
  • 0 關(guān)注
  • 122 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)