为什么电子邮件js在使用react应用程序时不发送邮件?

问题描述 投票:0回答:3

当我从我的 React 应用程序联系我们页面发送时,电子邮件 js 没有发送任何电子邮件,尽管当我从网站本身测试电子邮件时,电子邮件工作正常。这是我使用过的电子邮件js代码。我已经删除了不需要的部分。

function Contactme() {
  const form = useRef();
  function sendEmail(e){
    emailjs.sendForm('gmail', 'template_ppq****', form.current, 'iWxx2qNPr0xxu****')
    .then((result) => {
        console.log(result.text);
    }, (error) => {
        console.log(error.text);
    });
    e.target.reset();
  }
  return (
    <div>
      <div className="contact-box">
        <div className="details">
          <h2>Contact</h2>
          <p>Fill up the form to contact</p>
        </div>
        <div className="sendmsg">
          <form action="" onSubmit={sendEmail} ref={form}>
          <div className="contact-right name-input" name="name">
          Your Name
          <input type="text" className="contact-right-input email-input" name="from_name" />
          Your email
          <input type="text" className="contact-right-input message-input" name="email"/>
          Subject
          <input type="text" className="contact-right-input message-input" name="subject"/>
          Your message
          <textarea id="" cols="30" rows="10" style={{border:"1px solid lightblue"}} name="message"></textarea>
          <button className="contact-btn" >Submit</button>
          </div>
          </form>
        </div>
      </div>
    </div>
  )
}

html css reactjs email
3个回答
1
投票

将 ID 添加到您的输入字段,并确保该 ID 与您的 Emailjs 仪表板上的设置相同。我希望这有帮助


0
投票

这对我有用。在 emailjs.sendForm('gmail'........... 而不是 'gmail' 使用您的服务 IDthis one


0
投票

如果添加 ID 对您不起作用,请添加名称元素并确保它与您在 emailJs 模板中添加的名称匹配,如下所示;

        <input
          type="email"
          id="email"

          // this
          name="email"

          placeholder=" Your email"
          required
        />

欲了解更详细的解释请查看此

© www.soinside.com 2019 - 2024. All rights reserved.