Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

emailjs react npm

//npm install @emailjs/browser
import React, { useRef } from 'react';
import emailjs from '@emailjs/browser';

export const ContactUs = () => {
  const form = useRef();

  const sendEmail = (e) => {
    e.preventDefault();

    emailjs.sendForm('YOUR_SERVICE_ID', 'YOUR_TEMPLATE_ID', form.current, 'YOUR_USER_ID')
      .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>
  );
};

// seee doc for more info, https://www.emailjs.com/docs/examples/reactjs/
Comment

emailjs react

// send email using reactjs//

import React, { useRef } from 'react';
import emailjs from 'emailjs-com';

export const ContactUs = () => {
  const form = useRef();

  const sendEmail = (e) => {
    e.preventDefault();

    emailjs.sendForm('YOUR_SERVICE_ID', 'YOUR_TEMPLATE_ID', form.current, 'YOUR_USER_ID')
      .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>
  );
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: what is event loop in javascript 
Javascript :: udpdate records using axios http put method 
Javascript :: filtering jquery 
Javascript :: electron ipcmain send 
Javascript :: Find items from object 
Javascript :: define function 
Javascript :: run javascript in atom 
Javascript :: context api example in react 
Javascript :: javascript weakset 
Javascript :: get full height of element javascript 
Javascript :: _.pluck 
Javascript :: react native setTimeOut error 
Javascript :: javascript link detector 
Javascript :: add element in array 
Javascript :: string to array in js 
Javascript :: beautifulsoup for javascript 
Javascript :: error: Error: Unable to resolve module `crypto` from `node_modulescrypto-jscore.js`: crypto could not be found within the project. 
Javascript :: onkeypress 
Javascript :: react functional component 
Javascript :: Find a palindrome using Array methods 
Javascript :: readline nodejs 
Javascript :: javascript stack 
Javascript :: document.createelement with id 
Javascript :: fetch composition API in Vue3 
Javascript :: call function 
Javascript :: javascript break out of map 
Javascript :: crypto random string javascript 
Javascript :: create region in javascript 
Javascript :: firebase realtime database javascript 
Javascript :: react setstate synchronous 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =