-2
I own a site and I would like that when the user sent a message through the contact, the site sent me this message via email... already configured the sending and is working using NODEMAILER
const nodemailer = require ('nodemailer');
var assunto = 'teste';
var nome = 'teste2';
var email = '[email protected]';
var msg = 'teste 2 teste 2 teste 2';
let transporter = nodemailer.createTransport({
host: "mail.example.com",
port: 465,
secure: true,
auth: {
user:'[email protected]',
pass:'****minhasenhasupersegura****'
}
});
transporter.sendMail({
from: '<[email protected]>',
to: '[email protected]',
subject: assunto,
text: 'nome: ' + nome + ' Email: ' + email + ' -- mensagem: ' +msg,
});
the send form where I have the send button of the form is like this:
<form id='contatos'>
<div class="form-group">
<h2 id='tituloCont'>Envie sua mensagem</h2>
<label for="nomeCont" id='labelNome'>Seu nome</label>
<input type="text" class="form-control" id="nomeCont" placeholder="Digite aqui seu nome">
</div>
<div class="form-group">
<label for="motivoCont" id='labelMot'>Qual o motivo do contato ?</label>
<input type="text" class="form-control" id="motivoCont" placeholder="Digite aqui o motivo do seu contato">
</div>
<div class="form-group">
<label for="emailCont" id='labelMot'>Seu Email</label>
<input type="text" class="form-control" id="emailCont" placeholder="Digite aqui seu Email">
</div>
<div class="form-group">
<label for="textoCont" id='mensagemCont'>Digite sua mensagem</label>
<textarea class="form-control" id="textoCont" rows="4"></textarea>
</div>
<button id='enviarCont' onclick="envia()">
Enviar
</button>
</form>
I imagined doing something like :
$('#enviarCont').click(function(){
})
and paste inside it the code q is sending the Email... but it does not work...
Yes, it does not work, the nodemailer must be configured in the backend(nodejs). You must expose a published route that calls the e-mail sending. (via post) to your backend. So in your click action just call the endpoint with the form data.
– Danizavtz
But when I call at the prompt the Node index.js command (name of the file q ta send) it sends the email normally...
– Jujuba Dev
I don’t understand what you mean, can you show me ?? I’m caught up in it and it seems to be something so simple
– Jujuba Dev