2016-12-12 7 views
0

こんにちは私はスタックとプログラミングに新しいので、サーバーを実行してサーバーを実行すると、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"> 
 
\t <button id="emailAddress2" class="btn btn-secondary input2 emailbtn2 other" type="button" onclick ="validate()"> 
 
     <div class="emailbtn">></div> 
 
     </button> 
 
\t </span> 
 
    </form> 
 
</div>

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

 
\t var email = "[email protected]"; 
 
\t emailService.sendInvoiceEmail(email,function(data){ 
 
\t \t res.send("success"); 
 
\t }, 
 
\t function(error){ 
 
\t \t console.log(error); 
 
\t }) 
 
});

答えて

0

bodyparserミドルウェアを使用してフォーム値を読み取ります。これをメインファイルに含めます。

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

フォームから電子メールを読むにはreq.body.emailを使用してください。

関連する問題