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

162
Vistas
Angular form doesn't send data dynamically

I have a problem trying to dynamically grab the text and send it to my e-mail. It works when manually typing into TS onSendEmail. I am using free email hosting server and the assets folder has required files needed

HTML code

<form (ngSubmit)="onSendEmail(addEmailForm)" #addEmailForm ="ngForm">
  <fieldset>
    <legend>Contact us</legend>
    <label>Your name</label>  <br>
    <input ngModel  name="name" type="text" placeholder="Your name" size="20" required ><br> 
    <label>E-mail address</label>  <br>
    <input ngModel  name="email" type="text" placeholder="example@example.com" size="20" required><br>
    <label>Subject</label>  <br>
    <input ngModel  name="subject" type="text" size="20"><br>
    <label>Body</label>  <br>
    <textarea ngModel  name="body" type="text" cols="40" rows="6" required></textarea><br>
    <button [disabled]="addEmailForm.invalid" >Send</button>
    </fieldset>
</form> 

Typescript code

import { HttpClient } from '@angular/common/http';
import { Component, OnInit, AfterViewInit } from '@angular/core';
import { NgForm } from '@angular/forms';


declare let Email: any;
import 'src/assets/smtp.js';  // available in assets folder


@Component({
  selector: 'app-map',
  templateUrl: './shops.component.html',
  styleUrls: ['./shops.component.css']
})
export class ShopsComponent implements OnInit, AfterViewInit {

  constructor(private http: HttpClient) { }

  ngOnInit(): void { }  

  body: any
  subject: any;
  email: any;
  name: any;
 

  onSendEmail(addEmailForm: NgForm) {
    Email.send({
      Host : "smtp.elasticemail.com",
      Username : "myemail@hotmail.com",
      Password : "mypassword",
      To : 'mysecondemail@hotmail.com',
      Name: this.name,    
      From : this.email,     // when I write these manually the email gets sent
      Subject : this.subject,
      Body : this.body,
        }).then( 
    (message: any) => alert("E-mail sent, thank you.")
      );
  }

}


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

0

To get filled data from your from You should use:

  onSendEmail(addEmailForm: NgForm) {
let data = addEmailForm.value;
//...
}
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