0

I am trying follow this tutorial: https://html.form.guide/email-form/php-form-to-email/ to deploy a simple php script to google App Engine. I want to load the form from localhost and post to the app engine link. When I do, the $_POST is empty. Is this an issue when posting from another server/localhost to an app-engine hosted service?

Code:

app.yaml:

runtime: php55
api_version: 1
threadsafe: true

handlers:
- url: .*
script: formemailer.php

php script:

<?php
if(!isset($_POST['submit']))
{
    echo "error; you need to submit the form!";
}
?>

Form:

<form method="post" action="https://<url>.appspot.com/formemailer.php">
    <p>
        <label for='name'>Enter Name: </label><br>
        <input type="text" name="name">
    </p>
    <input type="submit" name="submit" value="submit" />
</form>
Matthew
  • 9,851
  • 4
  • 46
  • 77

3 Answers3

2

you can post data to another server by writing the true url if your url was ok the post data must be passed but if you checked your url and it's true but you still have a problem you can use api calls to do that by

header('Content-Type: application/json');
$data = json_decode(file_get_contents("php://input"));
header("Content-Type: application/json");
$name = $data->name;
$to = "yourmail@mail.com";
$message = $name . "hiii";
$subject = "test mail";
mail($to, $message, $subject);
        

by doing this you can make a api call with curl to do the mail function and pass the information from the server by curl request i hope you find this answer helpful and if mail() function didn't worked for you or gave you an error you can try phpmailer if you have any questions you can comment and i will answer them

  • Hi there - I have not been able to get back and test your suggestion - I will update when I do. Awarding the bounty before it runs out, thank you for taking the time to answer - stay tuned. – Matthew Jul 10 '21 at 16:23
1

Is this an issue when posting from another server/localhost to an app-engine hosted service?

No, the server receives the POST request as it is send.

And yes, as you have an issue doing so.


It should work, but what to do now?

Verify with the networking tools in your browser what is actually send to the server. This might already give you some more insights.

The networking tools are nowadays with your browser, please see:

or the documentation of your browser.


For a PHP 5 application running on Google App Engine you can find a dedicated tutorial handling form input at:

However strongly recommended is (not only on App Engine but in general) to use the PHP 7 runtime. This should be independent to your problem, however better start with PHP 7 from the beginning (if you allow me this comment).

The general information (also for PHP 5 and 7) is available here:

If you would like to learn about how PHP in general handles this, independent to any platform, you can find it outlined in the PHP manual here:

For the general handling in browsers for what you ask for - the form on one host (or even a HTML file locally) posting to another host, please see this related Q/A:

hakre
  • 193,403
  • 52
  • 435
  • 836
  • Thank you - I think my answer is in here - Satellite internet being what it is I only saw your detailed response after awarding the bounty to a cached load of the page. Will mark this accepted. – Matthew Jul 10 '21 at 16:26
0

appspot.com has been the host to a lot of fishing attacks. It is likely blocked as a safety issue.

Drivers Sea
  • 446
  • 2
  • 10