Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

396
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!