Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.post('/enviar', function(req,res){
- var name = req.body.nombre;
- var mail = req.body.correo;
- var messege = req.body.mensaje;
- var mail_from = "servicios@fractalservicios.com";
- var subject_from = "Contact web fractal nodejs";
- var transporter = nodemailer.createTransport(smtpTransport({
- host: "*****",
- port: ***,
- auth: {
- user: "****",
- pass: "****"
- }
- }));
- var mailOptions = {
- from: name + ' ' + mail, // sender address
- to: mail_from, // list of receivers
- subject: subject_from , // Subject line
- html: messege // html body
- };
- transporter.sendMail(mailOptions,function(error,result){
- if(error){
- console.log(error);
- console.log("salio mal");
- //res.end("error");
- res.render('error',{titulo: 'error al enviar menmsaje'});
- }else{
- console.log("Message sent: " + res.message);
- console.log("correcto");
- res.redirect('/');
- //res.render('enviado',{titulo: 'mensaje enviado'});
- }
- //res.redirect('/');
- });
- })
- var nombre = $('#nombre').val();
- var correo = $('#correo').val();
- var mensaje = $('#mensaje').val();
- var enviar_info = {
- "nombre": nombre,
- "correo": correo,
- "mensaje": mensaje
- };
- $('.send_mail').on('click',function(){
- $.ajax({
- type: "POST",
- url: "/enviar",
- data: JSON.stringify(enviar_info),
- contentType:"application/json; charset=utf-8",
- dataType: 'json',
- success: function(e){
- alert("genial se envio tu mensaje");
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement