I am building a website and cannot get the contact form working on it's designated page, when I click it I am supposed to see a url that says
index.php?=emailsent
However I am not getting this error, I am instead just getting sent to the file with the php code in it, this happens to be:
contactform.php
Anyway, here is the HTML code on the website that I am using
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="path/to/font-awesome/css/font-awesome.min.css">
<script src="https://kit.fontawesome.com/1891ffb665.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1 K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2 l" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css2?family=Bebas Neue&display=swap" rel="stylesheet">
<title> Contact us </title>
</head>
<div class="background">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C OGpamoFVy38MVBnE IbbVYUew OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>
<main>
<div class="contact-form">
<h1> Send us an Email </h1>
<form class="contact-form" action="contactform.php" method="post">
<input type="text" name="name" placeholder="Full name">
<input type="text" name="email" placeholder="Email address">
<input type="text" name="subject" placeholder="Subject">
<textarea name="message" placeholder="Insert message"></textarea>
<input type="submit" value="Send"></button>
</form>
</div>
</main>
</div>
</body>
</html>
Here is my Php code that is on the contactform.php file.
<?php
if (isset($_POST['send'])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['mail'];
$message = $_POST['message'];
$mailto = "[email protected]";
$headers = "From: ".$mailFrom;
$txt = "You've received an Email from ".$name.".\n\n".$message;
mail($mailto, $subject, $txt, $headers);
header("Location: index.php?emailsent");
}
?>
Sorry if I have missed anything, I can repost with more details if so, just getting near my deadline and this roadblock has me stumped.
CodePudding user response:
<input type="submit" value="Send" name="send"></input>
Explanation:
Since you're checking in your php file, isset($_POST['send'])
, you are not passing the name send to the request, that's why the statement goes falsy