Javascript 尝试将EmailJS与React一起使用时,服务ID无效
我在我的网站上创建了一个联系我的表单,为此我使用EmailJS。 但是,当我尝试通过联系人表单向自己发送邮件时,我收到一个400错误Javascript 尝试将EmailJS与React一起使用时,服务ID无效,javascript,reactjs,email,frontend,Javascript,Reactjs,Email,Frontend,我在我的网站上创建了一个联系我的表单,为此我使用EmailJS。 但是,当我尝试通过联系人表单向自己发送邮件时,我收到一个400错误服务ID无效。 我遵循了该教程的每个步骤,因为我以前没有使用过EmailJShttps://blog.mailtrap.io/react-send-email/ 这是我的联系人组件 class Contact extends React.Component { constructor(props) { super(pro
服务ID无效。
我遵循了该教程的每个步骤,因为我以前没有使用过EmailJShttps://blog.mailtrap.io/react-send-email/
这是我的联系人组件
class Contact extends React.Component {
constructor(props) {
super(props);
this.state = { feedback: '', name: 'Name', email: 'email@example.com' };
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
render() {
return (
<form className="test-mailing">
<h1>Let's see if it works</h1>
<div>
<textarea
id="test-mailing"
name="test-mailing"
onChange={this.handleChange}
placeholder="Post some lorem ipsum here"
required
value={this.state.feedback}
style={{width: '100%', height: '150px'}}
/>
</div>
<input type="button" value="Submit" className="btn btn--submit" onClick={this.handleSubmit} />
</form>
)
}
handleChange(event) {
this.setState({feedback: event.target.value})
}
handleSubmit() {
const templateId = 'template_id';
this.sendFeedback(templateId, {message_html: this.state.feedback, from_name: this.state.name, reply_to: this.state.email})
}
sendFeedback (templateId, variables) {
window.emailjs.send(
'gmail', templateId,
variables
).then(res => {
console.log('Email successfully sent!')
})
// Handle errors here however you like, or use a React error boundary
.catch(err => console.error('Oh well, you failed. Here some thoughts on the error that occured:', err))
}
}
这发生在我身上,是因为我没有激活帐户。
当你登录时,点击“电子邮件服务”并选择gmail和你的帐户
pd:GoogleTranslate要解决这个问题,我必须用我的服务ID替换掉“gmail”
sendFeedback (templateId, variables) {
window.emailjs.send(
***serviceID here***, templateId,
variables
).then(res => {
console.log('Email successfully sent!')
})
// Handle errors here however you like, or use a React error boundary
.catch(err => console.error('Oh well, you failed. Here some thoughts on the error that occured:', err))
}
我的web浏览器中的JavaScript控制台帮助识别了这一点。也有同样的问题。
为了解决这个问题
我必须粘贴的不是“gmail”字符串本身,而是服务id
在gmail图标下方
登录后在EmailJS网站中。每个人都有自己的具体号码。此外,模板id对于放置为模板生成的id也很重要
当您想要发布项目时,建议将特殊ID放在.env文件中以保持安全
sendFeedback (templateId, variables) {
window.emailjs.send(
***serviceID here***, templateId,
variables
).then(res => {
console.log('Email successfully sent!')
})
// Handle errors here however you like, or use a React error boundary
.catch(err => console.error('Oh well, you failed. Here some thoughts on the error that occured:', err))
}