【问题标题】:I'm not receiving my form input information to my inbox when using Emailjs使用 Emailjs 时,我没有在收件箱中收到表单输入信息
【发布时间】:2020-08-12 11:56:34
【问题描述】:

我最近开始使用 Emailjs 将表单输入信息接收到我自己的电子邮件地址。一切似乎都设置得很好,但(经过数小时的研究)似乎无法弄清楚为什么我没有收到任何输入信息。任何帮助将不胜感激!

HTML 代码

    <!--SCRIPT FOR EMAILjs-->

    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/emailjs-com@2.3.2/dist/email.min.js"></script>
    <script type="text/javascript">
        (function () {
            emailjs.init("user_xxxxxxxxxxxxxxxxxxxxx");
        })();
    </script>


    <!--LOCATION FORM-->

    <form class="contact_form" onsubmit="return sendMail(this);">
        <input type="text" name="full_name" class="form_inputs fullName_input" autocomplete="off" placeholder="Full Name"
            onfocus="this.placeholder = ''" onblur="this.placeholder = 'Full Name'">

        <input type="text" name="emailAddress" class="form_inputs emailAddress_input" autocomplete="off"
            placeholder="Email Address" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Email Address'">

        <p class="cleaningLocationTitle">Cleaning Location:</p>

        <input type="text" name="streetAddress" class="form_inputs streetAddress_input" autocomplete="off"
            placeholder="Street Address" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Street Address'"
            required>

        <input type="text" name="townCity" class="form_inputs townCity_input" autocomplete="off" placeholder="Town/City"
            onfocus="this.placeholder = ''" onblur="this.placeholder = 'Town/City'" required>

        <input type="text" name="postcode" class="form_inputs postcode_input" autocomplete="off" placeholder="Postcode"
            onfocus="this.placeholder = ''" onblur="this.placeholder = 'Postcode'">

        <textarea class="short_description_box" name="cleanRequest"
            placeholder="Please give a short description of your cleaning needs. i.e Washing dishes, vacuuming throughout..."
            onfocus="this.placeholder = ''"
            onblur="this.placeholder = 'Please give a short description of your cleaning needs. i.e Washing dishes, vacuuming throughout...'"></textarea>
    </form>


    <div class="findcleaner_buttonWrap">
        <button class="findcleaner_button" type="submit" onClick="location.href='mapsAPI.html'">Find me a cleaner
        </button>
    </div>

JAVASCRIPT 代码

function sendMail(contactForm) {
    emailjs.send("gmail", "contact_form", {
            "full_name": contactForm.fullname.value,
            "user_email": contactForm.emailAddress.value,
            "street_address": contactForm.streetAddress.value,
            "town_city": contactForm.townCity.value,
            "user_postcode ": contactForm.postcode.value,
            "clean_request  ": contactForm.cleanRequest.value,
        })
        .then(
            function (response) {
                console.log("success", response);
            },
            function (error) {
                console.log("FAILED", error);
            }
        )
}

【问题讨论】:

    标签: javascript html forms email


    【解决方案1】:

    在您的表单中,代码期望表单被提交以触发 EmailJs。但是,表单本身没有提交按钮(任何类型)来触发提交。相反,您在表单之外有一个提交按钮,将访问者重定向到mapsAPI.html

    我将提交按钮移到表单中,从按钮中删除了 onclick 处理程序,并将位置重定向添加到 emailjs 功能的成功。

      <!--SCRIPT FOR EMAILjs-->
    
        <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/emailjs-com@2.3.2/dist/email.min.js"></script>
        <script type="text/javascript">
            (function () {
                emailjs.init("user_xxxxxxxxxxxxxxxxxxxxx");
            })();
        </script>
    
    
        <!--LOCATION FORM-->
    
        <form class="contact_form" onsubmit="return sendMail(this);">
            <input type="text" name="full_name" class="form_inputs fullName_input" autocomplete="off" placeholder="Full Name"
                onfocus="this.placeholder = ''" onblur="this.placeholder = 'Full Name'">
    
            <input type="text" name="emailAddress" class="form_inputs emailAddress_input" autocomplete="off"
                placeholder="Email Address" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Email Address'">
    
            <p class="cleaningLocationTitle">Cleaning Location:</p>
    
            <input type="text" name="streetAddress" class="form_inputs streetAddress_input" autocomplete="off"
                placeholder="Street Address" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Street Address'"
                required>
    
            <input type="text" name="townCity" class="form_inputs townCity_input" autocomplete="off" placeholder="Town/City"
                onfocus="this.placeholder = ''" onblur="this.placeholder = 'Town/City'" required>
    
            <input type="text" name="postcode" class="form_inputs postcode_input" autocomplete="off" placeholder="Postcode"
                onfocus="this.placeholder = ''" onblur="this.placeholder = 'Postcode'">
    
            <textarea class="short_description_box" name="cleanRequest"
                placeholder="Please give a short description of your cleaning needs. i.e Washing dishes, vacuuming throughout..."
                onfocus="this.placeholder = ''"
                onblur="this.placeholder = 'Please give a short description of your cleaning needs. i.e Washing dishes, vacuuming throughout...'"></textarea>
    
    
    
        <div class="findcleaner_buttonWrap">
            <button class="findcleaner_button" type="submit">Find me a cleaner
            </button>
        </div>
    
    </form>
    
    function sendMail(contactForm) {
        emailjs.send("gmail", "contact_form", {
                "full_name": contactForm.fullname.value,
                "user_email": contactForm.emailAddress.value,
                "street_address": contactForm.streetAddress.value,
                "town_city": contactForm.townCity.value,
                "user_postcode ": contactForm.postcode.value,
                "clean_request  ": contactForm.cleanRequest.value,
            })
            .then(
                function (response) {
                    location.href='mapsAPI.html
                    console.log("success", response);
                },
                function (error) {
                    console.log("FAILED", error);
                }
            )
    }
    

    【讨论】:

    • 感谢您的帮助!我试试看
    猜你喜欢
    • 2014-03-07
    • 2012-10-17
    • 2020-10-28
    • 1970-01-01
    • 2020-11-25
    • 2016-12-19
    • 2012-07-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多