Lagoon Otter
Member
- Joined
- May 21, 2022
- Messages
- 17
- Reaction score
- 2
Hey guys,
PLEASE help. I have a website needs needs a (simple) email form. Of course HTML cannot natively do this so forced to use alternative methods, in my case PHP (which I know nothing about).
Currently have:
... snippet from HTML:
<form class="contact-form" action="contactform.php" method="post">
<input name="name" type="text" required class="form-input" placeholder="Name" tabindex="1">
<input name="mail" type="text" required class="form-input" placeholder="Your email" tabindex="2">
<textarea name="message" required="required" class="form-input-textarea" placeholder="Message" tabindex="3"></textarea>
<button class="form-btn" type="submit">Send</button>
</form>
and the contactform.php (saved on same level as index.html):
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$mailFrom = $_POST['mail'];
$message = $_POST['message'];
$mailTo = "//redacted//";
$headers = "From: ".$mailFrom;
$txt = "New email from ".$name.".\n\n".$message;
mail($mailTo, $txt, $headers);
header("Location: //redacted ... should this be the full https:// ... address??//?mailsend");
}
Uploaded the files to test directory, but when submitting the form the only result is that the contactform.php seems to try and load in the browser. No email received.
Somewhere something is wrong or am I missing something else that's crucial?
PLEASE help. I have a website needs needs a (simple) email form. Of course HTML cannot natively do this so forced to use alternative methods, in my case PHP (which I know nothing about).
Currently have:
... snippet from HTML:
<form class="contact-form" action="contactform.php" method="post">
<input name="name" type="text" required class="form-input" placeholder="Name" tabindex="1">
<input name="mail" type="text" required class="form-input" placeholder="Your email" tabindex="2">
<textarea name="message" required="required" class="form-input-textarea" placeholder="Message" tabindex="3"></textarea>
<button class="form-btn" type="submit">Send</button>
</form>
and the contactform.php (saved on same level as index.html):
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$mailFrom = $_POST['mail'];
$message = $_POST['message'];
$mailTo = "//redacted//";
$headers = "From: ".$mailFrom;
$txt = "New email from ".$name.".\n\n".$message;
mail($mailTo, $txt, $headers);
header("Location: //redacted ... should this be the full https:// ... address??//?mailsend");
}
Uploaded the files to test directory, but when submitting the form the only result is that the contactform.php seems to try and load in the browser. No email received.
Somewhere something is wrong or am I missing something else that's crucial?
Last edited: