Contact Form 2017 [duplicate]

-1

My question is simple and straightforward : Currently in 2017, with the advancement of Javascript ... Is there any way I can make a 100% contact form via javascript without using a PHP for example? If not, is there a tool as simple as PHP for this service? I do not understand anything about PHP , and wanted to make a contact form.

What exits do I have?

Thank you!

    
asked by anonymous 11.10.2017 / 22:33

1 answer

1

You will always need a backend that will send you email, this is indispensable (but using NodeJS, you do the sending, which is only JS).

An example of this using JS + NodejS

<input type="email" id="email">
<textarea id="msg"></textarea>
<button id="btn">Entrar em Contato</button>

<script>
   document.getElementById('btn').onclick = function(){
      let email = document.getElementById('email').value
      let msg = document.getElementById('msg').value

      // Exemplo usando axios
      axios.post('SUA URL', {
         email: email,
         msg: msg
      })
      .then(response => {
          alert('FOI')
      })
      .catch(error => {
          alert('ERRO')
      })
   }
</script>


// Do lado do servidor com Node

'use strict';
const nodemailer = require('nodemailer');

// Generate test SMTP service account from ethereal.email
// Only needed if you don't have a real mail account for testing
nodemailer.createTestAccount((err, account) => {

    // create reusable transporter object using the default SMTP transport
    let transporter = nodemailer.createTransport({
        host: 'smtp.ethereal.email',
        port: 587,
        secure: false, // true for 465, false for other ports
        auth: {
            user: account.user, // generated ethereal user
            pass: account.pass  // generated ethereal password
        }
    });

    // setup email data with unicode symbols
    let mailOptions = {
        from: '"Fred Foo                                     
11.10.2017 / 22:45