I've been working on getting a PHP email form set up on my personal webpage, and I am running into an issue where when I hit submit, the page displays "Cannot post /mail.php"
.
I've seen several similar questions on this site before, but I haven't found any approaches that have solved the issue. I am new to PHP so I'm not sure how deep the error could be, or if I'm possibly missing something obvious.
I'm using Brackets Live Preview on Mac OS Big Sur.
Things I've tried:
- Made sure that the mail.php file is in the same directory as my HTML files
- Made sure I'm setting the name attribute in my HTML file so the PHP can pick up on the relevant entered information
- Switched POST with GET (POST errors, GET download the PHP file instead of running it)
- Downloaded PHP with Homebrew
- Redownloaded Brackets
For reference this is my code: HTML File:
<form action="mail.php" method="post">
<p>Name</p> <input type="text" name="name">
<p>Email</p> <input type="text" name="email">
<p>Message</p><textarea name="message" rows="6" cols="40"></textarea><br>
<input type="submit" value="Send"><input type="reset" value="Clear">
</form>
PHP File:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From $name \n Message: $message";
$recipient = "email.redacted@gmail.com";
$subject = "Contact Form";
$mailheader = "From $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error");
?>
Any insight into what may be going wrong or some debugging steps to take would be much appreciated!