Как отправить электронное письмо
import React, { useRef } from "react";
import emailjs from "@emailjs/browser";
const ContactUs = () => {
const form = useRef();
const num =(Math.floor(Math.random() * 1000));
const sendEmail = (e) => {
e.preventDefault();
emailjs
.sendForm("gmail", "test-temp", e.target, "v8vKjhc4544PvRhT-")
.then(
(result) => {
console.log(result);
},
(error) => {
console.log(error.text);
}
);
e.target.reset();
};
return (
<form ref={form} onSubmit={sendEmail}>
<label>Subject</label>
<input type="text" name="subject" />
<label>Name</label>
<input type="text" name="name" />
<label>Email</label>
<input type="email" name="email" />
<label>Send to</label>
<input type="email" name="to_email" />
<label>Message</label>
<textarea name="message" />
<input name="randomNum" defaultValue={num}/>
<input type="submit" value="Send" />
</form>
);
};
export default ContactUs;
Stern