I'm trying to connect a simple contact form to send emails using React and PHP.
The problem I have is that every tutorial or article I've found either leaves out key parts that probably seem simple yet to a complete PHP beginner are all the difference between a working app or not. I have basically no experience with PHP and connecting a PHP file to a React app, I've downloaded Docker and Apache (yet have no idea how they fit into the picture), where to place the PHP file (if it even matters), how to host the PHP development server, etc...
I'm aware I should ideally spend some time reading through and actually learning PHP, it's something I plan to do, yet I'm pressed for time so that isn't currently an option.
The code I'm using is from this article https://blog.bitsrc.io/how-to-build-a-contact-form-with-react-js-and-php-d5977c17fec0
I currently have the PHP file placed like so: projectfolder -> php-folder -> index.php
and the React like so: projectfolder -> react-folder -> src --> (all the react files)
again, all the code is from the tutorial I linked and all I did was place the PHP from the article into the index.php file like above, and the same thing with the React code from the article (with the path names corrected) so I'm sure it's something I'm missing with the backend like setting up Docker or Apache, or possibly the file placement.
Sorry if this seems like a really broad question, essentially I just need to know the steps for correctly connecting a PHP file with a React app to send emails from a contact form.
Thanks
Related
I'm building small application to collect data. For data collection PHP is used, for data storage PostgreSQL is used. PostgreSQL is included so I have full control over it. The PHP for collection is triggered by external entity and I have no control over PHP interpreter that will run the code.
Is there a way how to load php_pgsql.dll? at run-time?
I know it was asked already, for example here, here and my best source of information was here. If I get it right there is no way if I'm not root of the system (because dl() was removed).
I can add PHP to my application the same way I have added PostgreSQL (to have control over PostgreSQL and do not need to ask someone to install, configure, maintain...), BUT my PHP files are triggered by external application so I have no control over used PHP interpreter/environment.
Is there a way to start from PHP code (let's call it systemPHP) the same PHP code but in different PHP environment (myPHP environment I have control over and where I will have the dll included)?
For example if systemPHP starts collect.php the pseudo code of collect.php will be:
if <this is myPHP> { # How to detect it?
<execute the data collection code>
}
else {
<Start collect.php in myPHP transfering all the data to it> # For example if started by apache then also headers, session information etc...
<Send back result from myPHP via the systemPHP>
}
How to achieve this PHP 'tunnel'?
Thanks for any help or hint. I know that best will be root or at least have intelligent admin, however this is not the case :-(
Currently I'm trying workaround by executing database tasks via shell and then getting response back in PHP, but sometimes it works sometimes not and I believe there is a better way of doing this (not to mention speed and resource usage).
Have you looked into using a messaging queue system? Write to the queue, then have your PHP script running that has php_pgsql.dll already loaded, which checks for new messages in the queue and processes them.
I am a PHP developer and I started learning Angular2. But I don't know how to use it with PHP.
Is it possible using Angular just as frontend?
What I must to do?
How to use it on shared hosting without Node.js installed?
My 2 cents as a long time PHP developer who has been playing with Angular2 quite a bit.
As a PHP developer, you're expecting to have your PHP render an HTML page and send to the client. You won't be doing that with Angular2. All that processing that would take place in PHP, building data tables, lists, or whatever is now Angular's job.
The only thing you're gonna do with PHP now is simply send JSON responses. Others have said this already above.
I'm assuming that since you're asking this you have little to no experience working with Angular2. So here's the deal:
Learn how to use Node and NPM on your local machine. Learn how to use NPM to set up your empty Angular2 project. Play and develop on your local machine.
When your ready to load in data, PHP can get involved by sending JSON data down to the front end for Angular to use.
When you're ready to put your Angular2 app online for the world you have a number of build options. You need to compile your code from Typescript to Javascript.
I've been using the Angular CLI tool. That lets me just run "ng build" and the app gets compiled.
Then I can upload the folder it generates up to my apache server and it works. The Angular CLI makes a folder called "dist" that contains all the stuff your front end will need.
Piece of cake.
Preferably, your site will just download a simple index.html and a file called app.js which contains all of your JS and therefore your Angular app.
PHP will be sitting on a server doing the job of an API, which is answering with JSON/XML to request, you angular app will then use the JSON to build the web interface.
You can have PHP hosted anywhere, and serve your angular app from another place, even thought it's not recommended because of latency
<html>
<script src="app.js">
</html>
as far as I know AngularJS is client side Javascript framework. So in general there's no need for 'nodejs'. You just need the AngularJS library files included in your HTML that's going to be produced by your PHP code.
I guess you should have a closer look at AngularJS at first.
above [sitesbyjoe] best answer is awesome.
Just details steps,
open cmd
1) cd your-project folder
2) ng build
3) copy dist folder to apache/htdocs/[dist/or your-project-name]
4) Important: open the index.html file, find <base href="/">
change it to <base href="/your-project-name/">
Without doing this, js file will not be load correctly.
5) http://localhost:80/your-project-name/index.html
It works.
Before this question gets closed, I know the setup above is possible. I just want clarification on some things.
I just started learning Aurelia because I want to convert one of my projects into a web app. My project is built with html+css+JavaScript(jQuery)+ PHP(MySql).
I havent used any sort of framework before.
In the guide, they mention a few ways to setup a web server. I used the http server with node. Now this is where I need some help understanding a few things.
I dont want to use node.js. I want to use PHP on the server. Will that work and how?
When using Apache server, I know any PHP page is sent to the interpreter that renders the final html. I use XAMPP and its apache comes bundled with PHP. Does the http server used by node come with PHP? Is this even a sensible question?
Now I know Aurelia is purely front end. If it used to make single page applications, it uses Ajax. So now I made the following assumption:
Using Aurelia, the user accesses the root page of the app that the web server sends. After that, Aurelia makes various Ajax requests to the server which will use my PHP files to do database query stuff.
Is that right or am I missing something. And can I just use xampp(apache) to host my app instead of server from node?
Aurelia is a framework that, after you export it to any server, does not rely on any back-end software at all. This means that with the help of the http- / fetch-client API, you can just call out to your php script.
I have an example in my github:
https://github.com/rjpvroegop/randyvroegop.nl-made-with-aurelia
Here I use the http-client to post data to my php script wich has a very simple email functionality.
You can see the action inside my view-model in src/pages/contact/index.js.
You can see the PHP script in src/assets/components/contactengine.php.
These work the way they should. Note: you have to change your gulp build if you want your PHP served the way I serve mine, from the dist folder after gulp-watch or gulp-export.
Next to that you can use any back-end functionality you would like, as long as it returns the proper data. This PHP script does that. If you would download my distribution to test this you can simply do the following:
gulp export from your terminal in the root folder
copy everything from the export folder to your PHP webserver.
This is a very similar to the question posed at Use php and simPro API to list customers.
The response to that question suggests downloading examples from GitHub. I have downloaded the SimPro examples at GitHub and have them functioning on the commandline.
I want to be able to use a web page as an intermediary between my FileMaker Pro database and the SimPro API. I can pass data to a web page written in PHP. It can convert the data to JSON and form a call to SimPro receive a response and display the success or failure as a web page.
Presently I have my JSON data hardcoded so that I can test the process. When run from a web browser I don't get a result, though the code works perfectly well running from the command line.
I'm not sure what I need to do make the examples web compatible. Can someone push me in the right direction?
Would be more than happy to help - could you post a snippet of your code - minus the auth info of course - so that I can try to assist?
Do you have your code printing anything else to the browser first - so that you make sure the script is actually executing as it should from the web server side - and have you checked your web server logs for any errors?
In some cases I've seen this is usually due to PHP config (there are separate configs for CLI and CGI in most setups) and can mean whilst libraries are loaded in one environment they may not be available to the other. The web server also usually requires a reload if you have just loaded libraries for use within your script.
Hope that helps.
Iam new to WebServer and iam using NanoHttpd , Everything work fine and i can connect to my phone using my web browser on my Computer, my problem is that iam trying to run a Php file manager app, called 'fsmanager' , work fine on my website i can browse my files etc, in my index.html i have a simple tag that target fsmanager.php, when i click it, im asked to download the php file, i have tried to add mime type php application/php etc with no luck, source code is same as NanoHttpd,
Any help would be appreciated, Thanks.
Take a look at "Quercus" (http://quercus.caucho.com/) from the folks who make the Resin App-Server. Its a complete implementation of PHP version 5 that runs on the JVM, as a servlet.
While NanoHttpd doesnt support the servlet API specifically, I am sure that you could write hooks to and from Quercus to get something running with NanoHttpd. That would be a fabulous extension to the existing webserver code! :-)
nanohttpd is purely an HTTP server, it will not execute PHP files on it's own.