我希望在成功或未成功发送电子邮件后返回成功消息。我的联系表单中的电子邮件发送正常,但我想在屏幕上显示一条消息,以表明该消息已成功发送。
这是我当前的.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);
}
);
}
答案 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()仅在调试处于活动状态时可见,并且仅用于开发/调试目的。