Hello fellow Stackoverflow members! I wrote this send form in PHP for my personal website, here's the code I wrote:
if($_SERVER["REQUEST_METHOD"] == "POST") {
$name = strip_tags(trim($_POST["name"]));
$name = str_replace(array("\r", "\n"), array(" ", " "), $name);
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$message = trim($_POST["message"]);
if(empty($name) OR empty($message) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
header("HTTP/1.1 400 Bad Request");
echo "Oops! There was a problem with your submission. Please complete the form and try again.";
exit;
}
$recipient = "montana@getprowl.com";
$subject = "General questions for you";
$email_content = "Name: $name\n";
$email_content .= "Email: $email\n\n";
$email_content .= "Message: \n$message\n";
$email_headers = "From: $name <$email>";
if(mail($recipient, $subject, $email_content, $email_headers)) {
header("HTTP/1.1 200 OK");
echo "Your message was sent successfully!";
} else {
header("HTTP/1.0 500 Internal Server Error");
echo "Your message wasn\'t sent, please try again.";
}
} else {
header("HTTP/1.1 403 Forbidden");
echo "There was a ploblem with your submission, please try again.";
}
When you enter information, I'll get the error that I wrote to popup which is Your message wasn't sent, please try again.
which is indicative of a HTTP 500 error, I'm thinking this could be solved via adding something in ".htacces" but honestly not sure what to put in there, have tried a couple of things but to avail. Thank you guys, any suggestions help.