Skip to content

Commit 7ae4550

Browse files
committed
first commit
1 parent 247f8e8 commit 7ae4550

File tree

6 files changed

+14873
-66
lines changed

6 files changed

+14873
-66
lines changed

README.md

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
1+
This is code for tutorial in my blog post [Create Contact form with react and php](http://blog.malith.pro/how-to-create-a-contact-form-with-react-js-and-php/).
22

3-
## Available Scripts
3+
## How to start
44

55
In the project directory, you can run:
66

@@ -12,33 +12,5 @@ Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
1212
The page will reload if you make edits.<br>
1313
You will also see any lint errors in the console.
1414

15-
### `npm test`
1615

17-
Launches the test runner in the interactive watch mode.<br>
18-
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
1916

20-
### `npm run build`
21-
22-
Builds the app for production to the `build` folder.<br>
23-
It correctly bundles React in production mode and optimizes the build for the best performance.
24-
25-
The build is minified and the filenames include the hashes.<br>
26-
Your app is ready to be deployed!
27-
28-
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29-
30-
### `npm run eject`
31-
32-
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33-
34-
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
35-
36-
Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
37-
38-
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
39-
40-
## Learn More
41-
42-
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43-
44-
To learn React, check out the [React documentation](https://reactjs.org/).

api/contact/index.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
header("Access-Control-Allow-Origin: *");
3+
$rest_json = file_get_contents("php://input");
4+
$_POST = json_decode($rest_json, true);
5+
6+
if( empty($_POST['fname']) && empty($_POST['email']) ) die();
7+
8+
if ($_POST){
9+
// set response code - 200 OK
10+
http_response_code(200);
11+
$subject = $_POST['fname'];
12+
$to = "me@malith.pro";
13+
$from = $_POST['email'];
14+
//data
15+
$msg = $_POST['number'] . $_POST['message'];
16+
//Headers
17+
$headers = "MIME-Version: 1.0\r\n";
18+
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
19+
$headers .= "From: <".$from. ">" ;
20+
21+
mail($to,$subject,$msg,$headers);
22+
//echo json_encode( $_POST );
23+
echo json_encode(array("sent" => true));
24+
} else {
25+
// tell the user about error
26+
echo json_encode(
27+
[
28+
"sent" => false,
29+
"message" => "Something went wrong"
30+
]
31+
);
32+
}
33+
?>

0 commit comments

Comments
 (0)