I am trying to get a contact form using the built in mail function to work but I'm running into some problems.
What I would like:
- On clicking 'submit' the form is sent to defined emailadres.php.
- If sent successfully, a confirmation message is displayed.
- If not sent, an error message is displayed.
What is currently happening:
- Confirmation message already shows on page load; regardless of form submission.
- Mail is not sent.
Code I'm using:
if ($_POST["submit"]) {
mail ($to, $subject, $body, $from);
$sendErr = "Your message has been sent";
} else {
$sendErr = "Your message could not be sent";
}
I'm fairly new to all this so any help figuring out where my thinking stalls would be appreciated. If I need to post more parts of the form I will.