我正在尝试将 emailjs 集成到我的 React 应用程序中来发送电子邮件。但是,我在控制台中收到错误消息:
“加载资源失败:服务器响应状态为 412 ()”
当我尝试发送电子邮件时。我检查了服务器日志,没有错误。
这是我正在使用的代码:
import emailjs from "@emailjs/browser"
// Function to handle sending the email
const handleSubmit = (e) => {
e.preventDefault()
setLoading(true)
emailjs
.send(
EMAILJS_SERVICE_ID,
EMAILJS_TEMPLATE_ID,
{
from_name: form.name,
to_name: "Umair ul islam",
from_email: form.email,
to_email: "[email protected]",
message: form.message,
},
EMAILJS_PUBLIC_KEY
)
.then(
() => {
setLoading(false)
alert("Thank you. I will get back to you as soon as possible.")
setForm({
name: "",
email: "",
message: "",
})
},
(error) => {
setLoading(false)
console.error(error)
alert("something went wrong. Please try again.")
}
)
}
我已检查 emailjs 文档,并且使用了正确的服务 ID、模板 ID 和用户 ID。
任何帮助将不胜感激。
当我在电子邮件地址等中使用大写字母时,我遇到了这个问题(错误 412)。当我更改为小写字母时,问题就消失了。