[英]How to send contact email with node js and mailgun?
new to node js and mail gun. Node js和Mail Gun的新功能。 I am trying to send a 'contact us' email from a website that is using the following for my send button (on my index.html page).
我正在尝试从网站发送“与我们联系”电子邮件,该网站的发送按钮使用以下命令(在index.html页面上)。
<!-- START CONTACT SECTION -->
<section class="section-contact" id="contacts">
<div class="container">
<!-- START SECTION HEADER -->
<h2 class="reveal reveal-top">Contact Us</h2>
<div class="subheading reveal reveal-top">
Hit us up. Let us know how we can make things better ( <b>Support@mail.com </b>).
</div>
<!-- END SECTION HEADER -->
<div class="contact-form-wrapper reveal reveal-bottom">
<!-- START CONTACT FORM -->
<!-- <form method="POST" action="./scripts/writeus.php" accept-charset="UTF-8" class="contact-form" id="jvalidate" novalidate="novalidate"> -->
<form method="POST" action="./scripts/mailgun.php" accept-charset="UTF-8" class="contact-form" id="jvalidate" novalidate="novalidate">
<!-- <form method="POST" action="send_mailgun($email)" accept-charset="UTF-8" class="contact-form" id="jvalidate" novalidate="novalidate"> -->
<div class="row">
<div class="col-sm-12 col-md-4">
<div class="field-holder">
<input class="form-control input-lg field" placeholder="John Snow" name="name" type="text">
</div>
</div>
<div class="col-sm-12 col-md-4">
<div class="field-holder">
<input class="form-control input-lg field" placeholder="myReplyEmail@Address.com" name="email" type="email">
</div>
</div>
<div class="col-sm-12 col-md-4">
<div class="field-holder">
<input class="form-control input-lg field" placeholder="Subject" name="website" type="text">
</div>
</div>
<div class="col-md-12 col-xs-12">
<div class="field-holder">
<textarea class="form-control" placeholder="Some text" name="message" cols="50" rows="10"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<div class="alert alert-success" role="alert" style="display: none;">
Message has been successfully sent.
</div>
<div class="alert alert-danger" role="alert" style="display: none;">
<div class="alert-text">Server error</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<button class="btn btn-primary btn-contact" type="submit" value="SEND MESSAGE">SEND MESSAGE</button>
</div>
</div>
</form>
<!-- END CONTACT FORM -->
</div>
</div>
</section>
<!-- END CONTACT SECTION -->
I have Node.js with Express and mailgun installed and working on my local machine with the snippet bellow hard coded as a test in my server.js 我安装了带有Express和mailgun的Node.js,并在本地计算机上工作,其中的代码段硬编码为server.js中的测试
var Mailgun = require('mailgun').Mailgun;
var mg = new Mailgun('some-api-key');
mg.sendText('example@example.com', 'Recipient 1 <rec1@example.com>',
'This is the subject',
'This is the text',
'noreply@example.com', {},
function(err) {
if (err) console.log('Oh noes: ' + err);
else console.log('Success');
});
How do I get the button info and send from my index.html ? 如何获取按钮信息并从index.html发送?
Thanks for the help. 谢谢您的帮助。 Much appreciated.
非常感激。
You need create web server to receive submit from your form or ajax call. 您需要创建Web服务器来接收来自表单或Ajax调用的提交。 Look this: http://expressjs.com/
看看这个: http : //expressjs.com/
example: 例:
var express = require('express');
var Mailgun = require('mailgun').Mailgun;
var app = express();
app.post('/sendMail', function (req, res) {
/*use body-parser (https://github.com/expressjs/body-parser) for parameters */
var mg = new Mailgun('some-api-key');
mg.sendText('example@example.com', 'Recipient 1 <rec1@example.com>',
'This is the subject',
'This is the text',
'noreply@example.com', {},
function(err) {
if (err) {
console.log('Oh noes: ' + err);
res.send('Error occurred');
}
res.send('Email sent');
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.