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

402
Vistas
Angular-PHP CORS request blocked

I am trying to send from my angular project an email via a php service at the time a form is filled out.

When I try to send the request in the console I get the following error "Access to XMLHttpRequest at 'https://website/assets/php/mail.php?con_name=user&con_email=mail&con_message=test&con_subject=Hello%20World' from origin 'https://website' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

As advised by many of you within the PHP file I have already unsuccessfully included "header('Access-Control-Allow-Origin: *');" and "header('Access-Control-Allow-Methods: POST, GET, OPTIONS');"

The angular call is:

sendMail() {
    
    this.mailValidator()
    if(this.validate() && this.mailValidator() )
    {
      this.http.get("https://website.com/assets/php/mail.php?con_name="+this.name+"&con_email="+this.email+"&con_message="+this.message+"&con_subject="+this.object).subscribe((val) => {
      
      })
      this.dialogRef.close();
    }
 
  } 

The PHP code is

<?php

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
echo("Test")

?>

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Could you try adding allow the Access-Control-Allow-Headers: Origin and see if that helps you ?

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: PUT, GET, POST");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
over 4 years ago · Santiago Trujillo 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