0

hey im new to ionic 3 i prepared a form of contact for my application where the server (php) has to send an email after the filling of the form by the user . in the server i use the function mail to send email by the server it works find and it sends email even with the appearence of error of No 'Access-Control-Allow-Origin' header
I already added the two headers in my php scripts

header("Access-Control-Allow-Origin: *"); header('Content-Type: text/html; charset=utf-8'); enter image description here

1 Answer 1

1

This is not a problem of your ionic app. The server you try to access via api call doens't support CORS. Hopefully this article helps you to solve your problem.

https://blog.ionicframework.com/handling-cors-issues-in-ionic/

There is a tutorial or solution to solve your problem.

Here is the important part for you

Dealing with CORS in Ionic CORS is only an issue when we are running or testing our app when running ionic serve or ionic run -l.

There are two ways to solve the issue: The first, and easier, solution is to just allow all origins from your API endpoint. However, we can’t always control the endpoint we are accessing. What we need, then, is a request that does not specify an origin.

We can do this by using a proxy server. Let’s look how the Ionic CLI provides an easily configurable proxy server.

Sign up to request clarification or add additional context in comments.

3 Comments

hello sir , how we can try the first solution i red this article many times but i had no idea on how dealing with this prb
If you are not the owner of this service you don't have a chance to allow all origins. It's a serverside deal. As he wrote "...solution is to just allow all origins from your API endpoint. However, we can’t always control the endpoint we are accessing. What we need, then, is a request that does not specify an origin."
The article describes how you have to deal with it. For your problem only the second solution will work if you are not the owner of the api service. I know that you have to read the article and cover some ground to get the knowledge but it will help you to get a better understanding of how this works. I also ran in those problems in my first javascript web project....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.