Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

120
Vistas
Sending email in Javascript

According to Sending emails with Javascript, one way to do it is the following:

function sendMail() {
    var link = "mailto:me@example.com"
             + "?cc=myCCaddress@example.com"
             + "&subject=" + encodeURIComponent("This is my subject")
             + "&body=" + encodeURIComponent(document.getElementById('myText').value)
    ;
    window.location.href = link;
}

However I'm trying to personalize it, sending emails with variables. I did this:

function sendMail(subject="test", body, mail="test@gmail.com") {
  var link = `mailto:${mail}`
           + "&subject=" + encodeURIComponent(`${subject}`)
           + "&body=" + encodeURIComponent(`${body}`)
  ;
  window.location.href = link;

But, when sending the email, I achieve this fail:

fail (image)

It seems like it is not recognizing each variable. How to solve it?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

The link have to be like that :

var link = `mailto:${mail}`
           + "?subject=" + encodeURIComponent(`${subject}`)
           + "&body=" + encodeURIComponent(`${body}`);
about 4 years ago · Juan Pablo Isaza Denunciar

0

The query string should be start with ? not &

change &subject to ?subject

it should be //abc@example.com?subject=blahblahblah&body=testtest

about 4 years ago · Juan Pablo Isaza Denunciar

0

Just try this code for sending email. I am sure it will work..

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script src="https://smtpjs.com/v3/smtp.js"></script>  
    <script type="text/javascript">
        function sendEmail() {
            Email.send({
                Host: "smtp.gmail.com",
                Username : "<sender’s email address>",
                Password : "<email password>",
                To : '<recipient’s email address>',
                From : "<sender’s email address>",
                Subject : "<email subject>",
                Body : "<email body>",
            })
            .then(function(message){
                alert("mail sent successfully")
            });
        }
    </script>
</head>
<body>  
    <form method="post">
        <input type="button" value="Send Email" onclick="sendEmail()"/>
    </form>  
</body>

And just remember if you are using JavaScript in any other file then just link it will your HTML file! And this is the not fully coded by me I have done some research from internet.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda