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

397
Visualizações
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 Respostas
Responde à pergunta

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 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