【问题标题】:Emailjs just working sometimes with Microsoft EdgeEmailjs 有时只能与 Microsoft Edge 配合使用
【发布时间】:2020-10-22 09:51:14
【问题描述】:

您好,我是 Web 开发的新手,我正在尝试使用 emailJS 发送一个简单的联系表单,一周前它可以从我的本地主机和 firebase 的托管站点工作,但我不知道发生了什么事情停止了正常工作,现在有时只能从 Microsoft Edge 浏览器中的 localhost 工作。如果我尝试在其中一个文本区域为空的情况下提交,则会弹出窗口警报,但是当我拥有所有字段时,它只会重新加载页面,但不会显示显示“已发送电子邮件!”的窗口警报 我按照本教程使用 EmailJS https://blog.mailtrap.io/react-send-email/#Sending_emails_with_EmailJS 我正在使用 ReactJS 开发网站,所以这里是我的联系表单组件的功能,感谢任何帮助!谢谢:D

这是我处理文本区域更改的地方

constructor(props) {
super(props);
this.state ={
  name: '',
  email: '',
  message: '',
}

this.handleChangeName = this.handleChangeName.bind(this);
this.handleChangeEmail = this.handleChangeEmail.bind(this);
this.handleChangeMessage = this.handleChangeMessage.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);;

这是我的登顶部分

handleChangeName(event) {
this.setState({name: event.target.value});
}
handleChangeEmail(event) {
this.setState({email: event.target.value});
}
handleChangeMessage(event) {;
this.setState({message: event.target.value});
}
handleSubmit(event) {
 event.preventDefault();
 const templateId = 'template_7HeYQshf';
 if(this.state.email === '' || this.state.name === '' || this.state.message === '')
 {
   window.alert('All fields are required.')
   window.location.reload();
 }
 else {
  this.sendFeedback(templateId, {message_html: this.state.message, from_name: this.state.name,
  reply_to: this.state.email})
 }
}   
sendFeedback (templateId, variables) {
window.emailjs.send(
  'gmail', templateId,
  variables
  ).then(res => {
    window.alert('Email sent!');  
    window.location.reload();      
  })
  // Handle errors here however you like, or use a React error boundary
  .catch(err => window.alert('something went wrong, please try again '))
  window.location.reload();
}

                                                                                          

【问题讨论】:

    标签: node.js reactjs email web contact-form


    【解决方案1】:

    我通过以下更改解决了这个问题:

    constructor(props) {
    super(props);
    this.state ={
      name: '',
      email: '',
      message: '',
    };
    this.handleChange = this.handleChange.bind(this);
    this.handleSubmit = this.handleSubmit.bind(this);
    }
    

    这是我的新峰会部分

    handleChange = (event) => {
    this.setState({[event.target.name]: event.target.value});
    };
    
    handleSubmit = (event) => {
    event.preventDefault();
    if(this.state.email === '' || this.state.name === '' || this.state.message === '')
    {
      window.alert('All fields are required.')
      window.location.reload();
    }
    else {
      emailjs.send(
        "gmail",
        "template_7HeYQshf",
        {message_html: this.state.message, from_name: this.state.name, reply_to: this.state.email},
        "*****"
      )
      window.alert('Email sent!')
      window.location.reload();
     } 
    }
    

    【讨论】:

      猜你喜欢
      • 2016-09-07
      • 1970-01-01
      • 2020-07-10
      • 2021-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-31
      • 1970-01-01
      相关资源
      最近更新 更多