I'm trying to send a welcome email for my app. I'm using the following form with a post method.
<form action="/signup" method="post">
<h1> Registro </h1>
<div class="usuario">
<label> Usuario </label> <br />
<input type="text" id="userSign" name="email" onFocus="entrarFoco(this)" onBlur="salirFoco(this); revisarObligatorio(this)">
</div> <!-- Cierre del usuario-->
<div class="password">
<label> Contraseña </label> <br />
<input type="password" name="password" onFocus="entrarFoco(this)" onBlur="salirFoco(this); revisarObligatorio(this)">
</div> <!-- Cierre del password-->
<button type="submit"> Registrarse </button>
</form>
Using express and passport I make the sign-up:
app.post('/signup',
passport.authenticate('local-signup', {
successRedirect : '/profile', //si los datos son correctos entraremos al perfil
failureRedirect : '/', //si hay un error o los datos no son correctos redirecciona a la página principal
})
);
I want to send an email once the user is succesfully registered. I'm using this code for that:
// email info
var api_key = '********'; //my apikey
var domain = '*********'; //my domain
var mailgun = require('mailgun-js')({apiKey: api_key, domain: domain});
var email = req.body.email;
console.log('email '+email);
// POST /sendmail
// curl --data "to=<email>, ..." http://localhost:3000/sendmail
var data = {
from: 'foodjoysocial@gmail.com',
to: email,
subject: 'Nuevo registro',
text: 'Testing some Mailgun awesomness!'
};
mailgun.messages().send(data, function (error, body) {
if (error) {
res.json(error);
} else {
console.log(body);
res.json(body);
}
});
I'm unable to get the email from the input texfield of my form using req.body.email. I've tried using an email instead of "req.body.name" and it works.
How can I get the user's email?