【问题标题】:How to send form data to email in React JS?如何在 React JS 中将表单数据发送到电子邮件?
【发布时间】:2022-11-11 13:48:15
【问题描述】:

我必须将表单数据发送到电子邮件地址。 我能怎么做? 我做了一些研究,我知道你必须使用图书馆来做到这一点。正确的? 你有什么建议?

【问题讨论】:

  • 是的,您必须为此使用图书馆,选择最适合您的图书馆

标签: reactjs


【解决方案1】:

我认为这个可能值得研究 - https://www.emailjs.com/docs/sdk/send-form/

【讨论】:

    【解决方案2】:

    如果您正在寻找实施反应然后像这样使用:

    // install @emailjs/browser
    import React, { useRef } from 'react';
    import emailjs from '@emailjs/browser';
    
    export const ContactUs = () => {
    const form = useRef();
    
    const sendEmail = (e) => {
    e.preventDefault();
    // service_id, templte_id and public key will get from Emailjs website when you create account and add template service and email service 
    emailjs.sendForm('YOUR_SERVICE_ID', 'YOUR_TEMPLATE_ID', form.current, 
    'YOUR_PUBLIC_KEY')
      .then((result) => {
          console.log(result.text);
      }, (error) => {
          console.log(error.text);
      });
    };
    
    return (
    <form ref={form} onSubmit={sendEmail}>
      <label>Name</label>
      <input type="text" name="user_name" />
      <label>Email</label>
      <input type="email" name="user_email" />
      <label>Message</label>
      <textarea name="message" />
      <input type="submit" value="Send" />
    </form>
    );
    };
    

    【讨论】:

      猜你喜欢
      • 2018-06-05
      • 2021-03-28
      • 2020-09-30
      • 2012-07-02
      • 1970-01-01
      • 1970-01-01
      • 2013-10-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多