首页 > 解决方案 > 如何在 reactJS 中使用 emailJS 向特定用户发送电子邮件

问题描述

我想向在我的 react 网站上发货的特定用户发送报价。我正在使用 emailjs,但它似乎不起作用。我想要一种非服务器端的方式来做到这一点。

这是我的代码:

const {freight, creatorsEmail} = useLocation().state; //creatoresEmail is the email of the user i want to send the email to.

 function sendEmail(e){
    e.preventDefault()
    
     emailjs.sendForm(
         "xxxxx",
         "xxxxxx",
          creatorsEmail,
         "xxxxx"
     ).then((res) => {
         if(res){
             firebase.firestore().collection("Quotations").add({
                 costPrice:costPrice,
                 sellPrice:sellPrice,
                 creatorsEmail:creatorsEmail,
                 freight:freight
             }).then((result) => {
                 alert("Quotation Sent Successfully")
                 window.location.reload()
             }).catch((e) => {
                alert("An Error Occured, Quotation Cannot be Sent")
                console.log(e)
             })
         }
       
     }).catch((e) => {
         alert("There was a problem")
         console.log(e)
     })
  }

               <Button
                color="primary"
                variant="contained"
                onclick={sendEmail} // in here would this be a correct way of calling the function sendEmail(e)?
              >
                Send Quotation
              </Button>

标签: javascriptnode.jsreactjsfirebaseemail

解决方案


推荐阅读