Help with HTML/CSS/PHP email form

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?
 
Last edited:
<?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");
}

Can you send a normal mail already without any variables?
Also try add the @ sign


E.g.
$headers = 'From: [email protected]'."\r\n".
'Reply-To: [email protected]'."\r\n" .
'X-Mailer: PHP/' . phpversion();

@mail("[email protected]", "Test Subject", "My Message", $headers);



------------------

It could also be that the POST submit doesnt work, try and print something to the webpage.
Does it print the text?

I.e. Keep debugging by printing to the website -- "Yes this happened" until you get to the point where it stops displaying the messages
 
Last edited:
If it is sending the email at all, it likely is being blocked due to DKIM and DMARC
 
Can you send a normal mail already without any variables?
Also try add the @ sign


E.g.
$headers = 'From: [email protected]'."\r\n".
'Reply-To: [email protected]'."\r\n" .
'X-Mailer: PHP/' . phpversion();

@mail("[email protected]", "Test Subject", "My Message", $headers);



------------------

It could also be that the POST submit doesnt work, try and print something to the webpage.
Does it print the text?

I.e. Keep debugging by printing to the website -- "Yes this happened" until you get to the point where it stops displaying the messages
Adding @ doesn't work – the line reads the 'mail' entry on the HTML side.

Um, how do you 'print' to the webpage?

If it is sending the email at all, it likely is being blocked due to DKIM and DMARC
Could be, but I don't think my server host uses DMARC (not sure about DKIM ... but have asked them bout this before).

What methods do you web devs use to build an email form??
 
Adding @ doesn't work – the line reads the 'mail' entry on the HTML side.

Um, how do you 'print' to the webpage?


Could be, but I don't think my server host uses DMARC (not sure about DKIM ... but have asked them bout this before).

What methods do you web devs use to build an email form??
Not php.

header("Location: //redacted ... should this be the full https:// ... address??//?mailsend");

This I think is meant to tell your browser to go back to the same page after sending the email. You can do the full URL or just a relative URL.

Was your smtp details set in php.ini?

how do you 'print' to the webpage?
 
Try work through this example.. it explains how every thing works and ties in together.. crucially, it includes error debugging and printing, so you can be made aware of any errors that's occurring.. debug logging is important in scenarios like this..
 
Okay: I have limited success with the following PHP:

<?php
if($_POST["message"]) {
mail("email.address.redacted", "Email from WCA",
$_POST["message"]. "From: [email protected]");
}
?>

A crucial part is that the same string also needs to be at the very top of the HTML doc (above <!doctype)

What I don't yet understand is what to place inside "From: [email protected]" – something there needs to read the HTML parameters of the form??
 
Plain old HTML built with Dreamweaver, nothing complicated needed in this case (the form is only name, email and message).

The dangerous part is I know literally nothing about PHP, so have very limited understanding of what I am looking at (a few bits makes sense, but I'm light years away from comprehension). Managed to get it all working this morning by running a different PHP script. And that's fine with me ... I do not need to understand every details; it works then it works.

Thanks for the input everyone.
 
Plain old HTML built with Dreamweaver, nothing complicated needed in this case (the form is only name, email and message).

The dangerous part is I know literally nothing about PHP, so have very limited understanding of what I am looking at (a few bits makes sense, but I'm light years away from comprehension). Managed to get it all working this morning by running a different PHP script. And that's fine with me ... I do not need to understand every details; it works then it works.

Thanks for the input everyone.

Lot's of free scripts
 
Plain old HTML built with Dreamweaver, nothing complicated needed in this case (the form is only name, email and message).

The dangerous part is I know literally nothing about PHP, so have very limited understanding of what I am looking at (a few bits makes sense, but I'm light years away from comprehension). Managed to get it all working this morning by running a different PHP script. And that's fine with me ... I do not need to understand every details; it works then it works.

Thanks for the input everyone.
Try and get something like recpatcha in place or you will get spammed to death.
 
Top
Sign up to the MyBroadband newsletter
X