如何获得emailjs返回成功消息?

时间:2018-11-29 23:42:17

标签: javascript email javascript-events

我希望在成功或未成功发送电子邮件后返回成功消息。我的联系表单中的电子邮件发送正常,但我想在屏幕上显示一条消息,以表明该消息已成功发送。

这是我当前的.js文件

function sendMail(contactForm) {
    emailjs.send("gmail", "minderfinder", {
        "from_name": contactForm.name.value,
        "from_email": contactForm.emailaddress.value,
        "booking_request": contactForm.booking_request.value,
        "mobile": contactForm.mobile.value,
        "date": contactForm.date.value,
        "time": contactForm.time.value
    })
    .then(
        function(response) {
            console.log("SUCCESS. status=%d, text=%s", response.status, response.text);
        },
        function(error) {
            console.log("FAILED", error);
        }
    );
}

1 个答案:

答案 0 :(得分:0)

您发布的代码段没有问题! 虽然,

function sendMail(contactForm) {
    emailjs.send("gmail", "minderfinder", {
        "from_name": contactForm.name.value,
        "from_email": contactForm.emailaddress.value,
        "booking_request": contactForm.booking_request.value,
        "mobile": contactForm.mobile.value,
        "date": contactForm.date.value,
        "time": contactForm.time.value
    })
    .then(
        function(response) {
            //console.log("SUCCESS. status=%d, text=%s", response.status, response.text);
            alert("Email sent successfully!");
        },
        function(error) {
            //console.log("FAILED", error);
            alert("FAILED!"+error);
        }
    );
}

这样可以解决您的问题,因为无法向用户显示消息!
console.log()仅在调试处于活动状态时可见,并且仅用于开发/调试目的。