坚持使用表单并发送电子邮件至输入电子邮件

时间:2016-12-12 06:56:46

标签: javascript node.js email

您好我是堆叠和编程的新手,所以我有一个节点项目,当我运行服务器时,它调用mandrill api并将我的电子邮件模板发送到硬编码的电子邮件,我想知道的是我如何获得来自表单输入字段的电子邮件值将其发送到服务器.js或任何地方,并将我的模板发送到该电子邮件

<div class="input-group emailInput emailInput2">
  <form method="post" action="/send-email/invoiceEmail">
    <input type="email" class="form-control input1 target" id="emailAddress" name="email" placeholder="Email Address">
    <span class="input-group-btn">
	  <button id="emailAddress2" class="btn btn-secondary input2 emailbtn2 other" type="button" onclick ="validate()">
        <div class="emailbtn">></div>
      </button>
	</span>
  </form>
</div>

app.post("/send-email/invoiceEmail", function (req, res) {
	var x = document.getElementById("emailAddress");
	console.log(req.body.email);

	var email = "mail@mail.com";
	emailService.sendInvoiceEmail(email,function(data){
		res.send("success");
	},
	function(error){
		console.log(error);
	})
});

1 个答案:

答案 0 :(得分:0)

使用bodyparser中间件读取表单值。将其包含在您的主文件中。

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

使用req.body.email从表单中读取电子邮件。