Global variable $_POST empty

Website URL

Error Message

I have a contact form with phpmailer. Everything seems to work fine, except that the form values ​​can’t be fetched, so an empty email is sent to my account. When i test it locally it works but when i upload the site the email it sends is empty.

The code is this:


//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load Composer's autoloader
require '../vendor/autoload.php';

$CONFIG = require("./config.php");

$to = $CONFIG["TO"];
$from = $CONFIG["FROM"];
$pass = $CONFIG["PASSAPP"];
$port = $CONFIG["PORT"];
$host = $CONFIG["HOST"];

$name = htmlspecialchars($_POST['name']);
$email = htmlspecialchars($_POST['email']);
$subject = htmlspecialchars($_POST['subject']);
$message = htmlspecialchars($_POST['message']);

$message = str_replace("\n.", "\n..", $message);

//Create an instance; passing `true` enables exceptions
$mail = new PHPMailer(true);

try {
    //Server settings
    $mail->Mailer = "smtp";
    $mail->SMTPAuth   = true;
    $mail->SMTPSecure = "tls";
    $mail->Host       = $host;
    $mail->Username   = $from;
    $mail->Password   = $pass;
    $mail->Port       = $port;

    $mail->CharSet = "UTF-8";
    $mail->Subject = $subject;
    $mail->Body = "<strong>From:</strong> $name<br><strong>Email:</strong> $email:<br><hr>$message";

    $res = ["status" => true, "message" => "El mensaje ha sido enviado."];
} catch (Exception $e) {
    $res = ["status" => false, "message" => "Error de servidor. Intentar más tarde."];

I went to see what was happening
I see that it retrieves data from the form properly

and then it has redirection because it assumes that this is file, but it is not, it is dir
so that’s why it redirects and adds a slash / to the end

but you deleted the contact form and I don’t see anything anymore


Please note that POST requests, and any data submitted to it, do not persist across redirects. So the redirect adding the slash by default will cause the POST request to turn into a GET request.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.