Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
Send email from HTML page using JS

I'm trying to send a mail from a html page using the below:

<script>
    function sendMail() {
    var link = "mailto:email@live.co.uk &subject=" + encodeURIComponent(document.getElementById('myText').value)
             + "&body=" + encodeURIComponent(document.getElementById('myText2').value)
    ;
    
    window.location.href = link;
}
  </script>


 <!-- Contact Form -->
 <div class="col-md-6 contact">
    <form role="form">
               <!-- Name -->
               <div class="row">
                   <div class="col-md-6">
                       <!-- E-Mail -->
                       <div class="form-group">
                           <input type="text" class="form-control" placeholder="Your name" id="myText">
                       </div>
                   </div>
                   <div class="col-md-6">
                       <!-- Phone Number -->
                       <div class="form-group">
                           <input type="email" class="form-control" placeholder="Email address">
                       </div>
                   </div>
               </div>
               <!-- Message Area -->
               <div class="form-group">
                   <textarea class="form-control" placeholder="Write you message here..." style="height:232px;" id="myText2"></textarea>
               </div>
               <!-- Subtmit Button -->
               <button type="submit" class="btn btn-send" onclick="sendMail(); return false">
                   Send message
               </button>
           </form>
 </div>

When I press button to click all of the data ends up in the default mail apps "To:" Text input area. Can anyone tell me how to split out the subject and body correctly?? I'd like these to go into the subject and body sections of the email by default.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Your query string variables should start with "?", not "&".

var link = "mailto:email@live.co.uk?subject=" + encodeURIComponent(document.getElementById('myText').value)
             + "&body=" + encodeURIComponent(document.getElementById('myText2').value)
    ;
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda