英文:
I use the function emailjs.send to send email. Why it shows https://api.emailjs.com/api/v1.0/email/send 422
问题
导入 emailjs from 'emailjs-com';
异步函数 发送邮件() {
尝试 {
const serviceID = '...';
const templateID = '...';
const userID = '...';
const emailParams = {
to_email: '...',
from_name: 'Your Name',
message: 'Hello, this is the email content.'
};
const response = await emailjs.send(serviceID, templateID, emailParams, userID);
console.log(response)
console.log('邮件发送成功');
} 捕获 (错误) {
console.error('发送邮件失败:', 错误);
console.log("??")
}
}
函数 App() {
返回 (
<>
<button type="button" onClick={发送邮件}>发送</button>
</>
);
}
导出 默认 App;
英文:
import emailjs from 'emailjs-com';
async function sendEmail() {
try {
const serviceID = '...';
const templateID = '...';
const userID = '...';
const emailParams = {
to_email: '...',
from_name: 'Your Name',
message: 'Hello, this is the email content.'
};
const response = await emailjs.send(serviceID, templateID, emailParams, userID);
console.log(response)
console.log('Email sent successfully');
} catch (error) {
console.error('Failed to send email:', error);
console.log("??")
}
}
function App() {
return (
<>
<button type="button" onClick={sendEmail}>Send</button>
</>
);
}
export default App;
Filed to send email: EmailJSResponseStatus {status: 422, text: 'The recipient address is empty'}
But the function emailjs.sendForm can work.
How should correct my code?
答案1
得分: 1
Replace 'to_email' with 'user_email'.
英文:
Replace 'to_email' with 'user_email'.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论