当我从我的 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>
)
}
将 ID 添加到您的输入字段,并确保该 ID 与您的 Emailjs 仪表板上的设置相同。我希望这有帮助
如果添加 ID 对您不起作用,请添加名称元素并确保它与您在 emailJs 模板中添加的名称匹配,如下所示;
<input
type="email"
id="email"
// this
name="email"
placeholder=" Your email"
required
/>
欲了解更详细的解释请查看此