-1

I am not able to send email from my website (developed using HTML, CSS, JavaScript).

I get following error message when i send email:

Access to XMLHttpRequest at 'http://mobilfiksern.no/contactform.php' from origin 'http://www.mobilfiksern.no' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Can any one please help me to fix this issue?

Thelouras
  • 852
  • 1
  • 10
  • 30
Nadeem
  • 1

1 Answers1

0

Every page top, or common top php file please add the following line.

<?php
//Session start section
?>    
<?php

//Need to add the following codes
$origin = $_SERVER['HTTP_ORIGIN'];
// PHP 7.x version array
$allowed_domains = ['http://mobilfiksern.no','http://www.mobilfiksern.no'];
// PHP 5.x version array
//$allowed_domains = array("http://mobilfiksern.no", "http://www.mobilfiksern.no");

if (in_array($origin, $allowed_domains)) {
    header('Access-Control-Allow-Origin: ' . $origin);
}
?>
<?php
//Usual codes
?>
<?php //Start the html tags ?>
<html>
Maths RkBala
  • 2,207
  • 3
  • 18
  • 21
  • This is not working for me. Problem is in Ajex request. If I comment code with Ajex request then no error message but email is also not send then. with Ajex request there is error of CORS – Nadeem Jan 03 '19 at 10:57