简体   繁体   中英

How to send submitted forms in ionic apps to email?

I have an Ionic app and contact form page (with Name, Email, and Phone). After the user clicks the Submit button, I want this form data to be sent to my E-mail. How do I do this?

You'd need to setup some kind of REST api, so that when the user clicks on the submit button, the data in the contact form is sent to the REST api you've set up, which will trigger it to send an email to you with the contents of the user's message.

Since you've tagged this with Node.JS, I would suggest that you have the contact form's action be send to something like ' http://yoursite.com/sendemail/ ' and then your API would handle the call with something like:

router.route('/sendemail/')
.post(function(req, res) {
    var userInput = req.body;
    var message = {
     text:    userInput.message,
     from:    userInput.name + ' <' + userInput.email + '>',
     to:      'youremail@email.com',
     subject: userInput.subject,
     attachment:
     [
        {data: this.text, alternative:true},
     ]
  };
  server.send(message, function(err, message) {
    if(err) {
      res.status(400);
      console.log(err);
    } else {
      res.status(200)
    }
  });
});

(you'll need to change some variables to fit your code)

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM