【问题标题】:Sending form data to specific email address using react-form使用 react-form 将表单数据发送到特定的电子邮件地址
【发布时间】:2017-12-10 15:37:00
【问题描述】:

我正在使用React Form 在基本的 React 登录页面中创建一个联系表单,并且我希望在用户按下提交时将数据发送到特定的电子邮件地址(例如 info@info.com)。如果这是一个菜鸟问题,我很抱歉,但我似乎找不到答案!

//the state  
constructor(props) {
super(props);
//this.handleSubmit = this.handleSubmit.bind(this);
this.state = {};

}

//the form
<Form onSubmit={submittedValues => this.setState( { submittedValues } )}>
        { formApi => (
          <form onSubmit={formApi.submitForm} id="form2">
            <label htmlFor="firstName">First name</label>
            <Text field="firstName" id="firstName" />
            <label htmlFor="lastName">Last name</label>
            <Text field="lastName" id="lastName" />
            <label htmlFor="email">Email"</label>
            <Text field="email" id="email" />
            <label htmlFor="subject">Subject</label>
            <Text field="subject" id="subject" />
            <label htmlFor="message">Message</label>
            <TextArea field="message" id="message" />
            <button type="submit" className="mb-4 btn btn-primary">Submit</button>
          </form>
        )}
      </Form>

【问题讨论】:

    标签: javascript forms reactjs


    【解决方案1】:

    您可以通过以下步骤来做到这一点:

    1. 首先,您需要在后端(服务器端)有一个脚本,该脚本会发送一封电子邮件,无论您传递什么数据。
    2. 其次,您需要向服务器端的该脚本发送一个 Ajax 请求,并通过电子邮件传递您需要发送的所有数据。

    如果您在服务器端使用 PHP,您可以使用 PHP 的邮件功能,或者您可以使用您选择的任何库。

    【讨论】:

      猜你喜欢
      • 2017-01-30
      • 1970-01-01
      • 2018-06-05
      • 2012-07-02
      • 1970-01-01
      • 1970-01-01
      • 2014-04-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多