我遵循本教程:https://github.com/SpaceG/NodeMailerForm
虽然在我的情况下,我还在使用Angular。我已经验证该教程正常工作。问题是当我点击提交按钮时出现以下错误。
我必须澄清一下,我在控制台上没有收到任何错误消息。
form1.html
<h3 class="text-center">¡Consigue tu seguro ahora!</h3>
<br>
<p class="bg-info" id="msg"></p>
<form ng-controller="repeatSeguros" id="emailForm" method="post" role="form">
<div class="form-group">
<select class="form-control form-control-lg" name="seguro">
<option selected>Elije un seguro</option>
<option>Seguro Auto</option>
<option>Vida</option>
<option>Hogar</option>
</select>
</div>
<div class="form-group">
<input type="email" class="form-control form-control-lg" name="email" placeholder="E-mail" required="required">
</div>
<p class="">
<input type="checkbox" checked class="mr-2"> He leído y aceptado los <a href="#">términos y condiciones</a> sobre el tratamiento de datos.
</p>
<button type="submit" class="btn btn-primary btn-block btn-lg" id="send">Quiero información</button>
</form>
<script>
$(function(){
var fullUrl = location.protocol+'//'+location.hostname+(location.port ? ':'+location.port: '');
$("#send").click(function(){
var formData = $("#emailForm").serialize();
$("#msg").text("Enviando requerimiento ...");
$.ajax({
url: fullUrl+'/send',
type: 'POST',
data: formData,
success: function(result) {
$("#msg").empty().text(result);
},
error: function(e) {
$("#msg").empty().text("There is some error to send email, Error code:"+e.status +", Error message:"+e.statusText);
},
dataType: "html",
timeout: 60000
});
});
});
</script>
&#13;
server.js
/*
Configuración envío de e-mail
*/
var http=require('http');
var express=require('express');
var nodemailer = require("nodemailer");
var bodyParser = require('body-parser')
var app=express();
var port = Number(process.env.PORT || 5000);
app.use(bodyParser.json()); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ extended: true }));
app.use('/', express.static(__dirname + '/'));
var path = require('path');
// Home page
app.all('/*',function(req, res, next){
res.sendFile('index.html', { root: __dirname });
//console.log
console.log('NodeMailer reading console log...' + req.url);
});
// sending mail function
app.post('/send', function(req, res){
if(req.body.email == "" || req.body.seguro == "") {
res.send("Error: Email & Seguro should not blank");
return false;
}
// Sending Emails with SMTP, Configuring SMTP settings
var smtpTransport = nodemailer.createTransport({
host: "smtp.gmail.com", // hostname
secureConnection: true, // use SSL
port: 465, // port for secure SMTP
secure: true,
auth: {
user: '************@gmail.com',
pass: '*********'
}
});
var mailOptions = {
from: 'Lorem ipsum <*********@gmail.com>', // sender address
to: '*********@*********.com, *********@*********.com', //+ req.body.email, // list of receivers
subject: 'Lorem ipsum - Lorem ipsum', // Subject line
//text: "Hello world ✔", // plaintext body
html:
'XXX: <br><br>' +
'XXX: ' + req.body.seguro + '<br>' +
'XXXX: ' + req.body.email
}
smtpTransport.sendMail(mailOptions, function(error, response){
if(error){
res.send("Email could not sent due to error: "+error);
}else{
res.send("Requerimiento enviado con éxito");
}
});
});
// Starting server
var server = http.createServer(app).listen(port, function() {
console.log("Server is Running on 127.0.0.1:" + port);
});
&#13;
的index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Previsora - Corredores de Seguro</title>
<link rel="stylesheet" type="text/css" href="node_modules/bootstrap/dist/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="custom.css">
<link rel="stylesheet" type="text/css" href="fonts/siloSoft.css">
</head>
<body ng-app="previsoraApp">
<div ng-include='"views/header.html"'></div>
<div class=""><ui-view></ui-view></div>
<div ng-include='"views/footer.html"'></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="node_modules/popper.js/dist/umd/popper.min.js"></script>
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="node_modules/angular/angular.min.js"></script>
<script src="node_modules/angular-ui-router/release/angular-ui-router.min.js"></script>
<script src="app.js"></script>
</body>
</html>
&#13;
app.js
var myApp = angular.module('previsoraApp', ['ui.router']);
myApp.config(function($stateProvider) {
var inicio = {
name: 'inicio',
url: '/',
templateUrl: 'views/inicio.html'
}
var seguroPersonas= {
name: 'seguroPersonas',
url: '/seguroPersonas',
templateUrl: 'views/seguroPersonas.html'
}
var seguroEmpresas= {
name: 'seguroEmpresas',
url: '/seguroEmpresas',
templateUrl: 'views/seguroEmpresas.html'
}
var nosotros= {
name: 'nosotros',
url: '/nosotros',
templateUrl: 'views/nosotros.html'
}
var contacto= {
name: 'contacto',
url: '/contacto',
templateUrl: 'views/contacto.html'
}
//Seguros Personas
var salud= {
name: 'salud',
url: '/salud',
templateUrl: 'views/segurosPersonas/salud.html'
}
var auto = {
name: 'auto',
url: '/auto',
templateUrl: 'views/segurosPersonas/auto.html'
}
var hogar = {
name: 'hogar',
url: '/hogar',
templateUrl: 'views/segurosPersonas/hogar.html'
}
var vida = {
name: 'vida',
url: '/vida',
templateUrl: 'views/segurosPersonas/vida.html'
}
var educacion = {
name: 'educacion',
url: '/educacion',
templateUrl: 'views/segurosPersonas/educacion.html'
}
var soatVehicular = {
name: 'soatVehicular',
url: '/soatVehicular',
templateUrl: 'views/segurosPersonas/soatVehicular.html'
}
var soatMotos = {
name: 'soatMotos',
url: '/soatMotos',
templateUrl: 'views/segurosPersonas/soatMotos.html'
}
//Seguros Empresas
var multiriesgo = {
name: 'multiriesgo',
url: '/multiriesgo',
templateUrl: 'views/segurosEmpresas/multiriesgo.html'
}
var vehiculares = {
name: 'vehiculares',
url: '/vehiculares',
templateUrl: 'views/segurosEmpresas/vehiculares.html'
}
var transporte = {
name: 'transporte',
url: '/transporte',
templateUrl: 'views/segurosEmpresas/transporte.html'
}
var trec = {
name: 'trec',
url: '/trec',
templateUrl: 'views/segurosEmpresas/trec.html'
}
var sctr = {
name: 'sctr',
url: '/sctr',
templateUrl: 'views/segurosEmpresas/sctr.html'
}
var vidaLey = {
name: 'vidaLey',
url: '/vidaLey',
templateUrl: 'views/segurosEmpresas/vidaLey.html'
}
var empleados = {
name: 'empleados',
url: '/empleados',
templateUrl: 'views/segurosEmpresas/empleados.html'
}
//Vistas
$stateProvider.state(inicio);
$stateProvider.state(seguroPersonas);
$stateProvider.state(seguroEmpresas);
$stateProvider.state(nosotros);
$stateProvider.state(contacto);
//Seguros Personas
$stateProvider.state(salud);
$stateProvider.state(auto);
$stateProvider.state(hogar);
$stateProvider.state(vida);
$stateProvider.state(educacion);
$stateProvider.state(soatVehicular);
$stateProvider.state(soatMotos);
//Seguros Empresas
$stateProvider.state(multiriesgo);
$stateProvider.state(vehiculares);
$stateProvider.state(transporte);
$stateProvider.state(trec);
$stateProvider.state(sctr);
$stateProvider.state(vidaLey);
$stateProvider.state(empleados);
});
&#13;