如何将离子应用中提交的表单发送到电子邮件?

时间:2017-03-30 23:47:31

标签: javascript php angularjs node.js ionic2

我有一个Ionic应用程序和联系表单页面(包括姓名,电子邮件和电话)。 用户单击“提交”按钮后,我希望将此表单数据发送到我的电子邮件。我该怎么做呢?

1 个答案:

答案 0 :(得分:0)

您需要设置某种REST api,以便当用户点击提交按钮时,联系表单中的数据将被发送到您设置的REST API,这将触发它发送发送给您的电子邮件,其中包含用户信息的内容。

由于您已使用Node.JS对此进行了标记,因此我建议您将联系表单的操作发送到类似“http://yoursite.com/sendemail/”的内容,然后您的API将使用以下内容处理调用:

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)
    }
  });
});

(您需要更改一些变量以适合您的代码)

希望这有帮助!