【发布时间】:2022-11-11 13:48:15
【问题描述】:
我必须将表单数据发送到电子邮件地址。 我能怎么做? 我做了一些研究,我知道你必须使用图书馆来做到这一点。正确的? 你有什么建议?
【问题讨论】:
-
是的,您必须为此使用图书馆,选择最适合您的图书馆
标签: reactjs
我必须将表单数据发送到电子邮件地址。 我能怎么做? 我做了一些研究,我知道你必须使用图书馆来做到这一点。正确的? 你有什么建议?
【问题讨论】:
标签: reactjs
我认为这个可能值得研究 - https://www.emailjs.com/docs/sdk/send-form/
【讨论】:
如果您正在寻找实施反应然后像这样使用:
// 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>
);
};
【讨论】: