I use the function emailjs.send to send email. Why it shows https://api.emailjs.com/api/v1.0/email/send 422

huangapple go评论64阅读模式
英文:

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'.

huangapple
  • 本文由 发表于 2023年5月11日 19:24:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76227089.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定