我在我的网站上设置了emailJS,以便人们向我发送消息。一切都很顺利,邮件也发了。但是,表单的内容不会在电子邮件中发送。
邮件中姓名、邮箱地址、主题、留言均为空。下面是我的代码以及我收到的电子邮件的图像。
反应代码:
const handleSendMessage = (e) =>{
e.preventDefault();
console.log(form.current);
emailjs.sendForm(process.env.REACT_APP_EMAILJS_SERVICE_KEY, process.env.REACT_APP_EMAILJS_TEMPLATE_NAME, form.current, process.env.REACT_APP_EMAILJS_PUBLIC_KEY)
.then((result) => {
console.log(result.text);
}, (error) => {
console.log(error.text);
});
}
<form ref={form} id='contact-form' onSubmit={handleSendMessage}>
<input className='contact-form-input' id='contact-full-name' placeholder='Full Name' type='text' name="name" required/>
<label htmlFor='name' className='contact-form-label-name'>Full Name</label>
<input className='contact-form-input' id='contact-email-address' placeholder='Email Address' type='email' name='email' required/>
<label htmlFor='email' className='contact-form-label-email'>Email Address</label>
<input className='contact-form-input' id='contact-subject' placeholder='Subject' type='text' name='subject' required/>
<label htmlFor='subject' className='contact-form-label-subject'>Subject</label>
<textarea name='message' id='contact-form-message' placeholder='Message' required/>
<label htmlFor='message' className='contact-form-label-message'>Message</label>
<div className='contact-form-submit-container'>
<input type='submit' id='contact-form-submit-btn' name='submit' value='Send Message'/>
</div>
</form>
EmailJS模板:
A new message has been sent from the contact page.
Message Senders full name: {{{name}}}
Message Sender's email: {{{email}}}
Message subject: {{{subject}}}
Message: {{{message}}}
电子邮件图片:图片
在做了一些混乱之后,我简单地改变了form.currente.target一切似乎都很顺利。