Why form submission redirects me to php file?

Viewed 34

I'm using PHP mailer to send the email with the data. I have form submission set up locally using XAMPP. It works perfectly and after I submit form, I receive an email with the data specified.

But the issue comes when I try my app on vercel or netlify, after submitting the form it redirects me to email.php. Can you please help me figure out why ?

email.php :

<?php

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'vendor/autoload.php';

$mail =  new PHPMailer(true);
$name = $_POST['name'];
$surname = $_POST['surname'];
$email = $_POST['email'];
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'smtp.mailtrap.io';
$mail->SMTPAuth = "true";
$mail->SMTPSecure = "tls";
$mail->Port = 2525;
$mail->Username = '4b4f48f1dfda19';
$mail->Password = '77ba1bf500d113';

$mail->setFrom('mnosov622@gmail.com');

$mail->addAddress('mnosov622@gmail.com');
$mail->Subject = 'Zayavka s sayta';

$mailContent = $name . ' ' . $surname;

$mail->Body = $mailContent;


if($mail->Send()) {
    echo "Email Sent...!";
    header('Location: thanks.html');

    exit;
}

else {
    echo "error";
}

$mail->smtpClose();

?>

index.html

<form action="email.php" method="POST">
        <input type="text" name="name" id="" placeholder="Your name">
        <input type="text" name="surname" id="" placeholder="Your surname">
        <input type="email" name="email" id="" placeholder="Email">
        <button type="submit">Отправить</button>
    </form>

Here is the app on [netlify][https://soft-dolphin-415c64.netlify.app/].

Thank you so much in advance!

1 Answers

Netlify is for modern static websites, so the answer is that you cannot run php on Netlify at run time

See their related official Q & A below

https://answers.netlify.com/t/how-to-host-php-websites/7410
Related