So I have a form:
<form method="post" action="contactus.php?message=ok" name="myForm" autocomplete="off">
<label for="Name">Name:</label>
<input type="text" name="Name" id="Name" maxlength="60" required/>
<label for="email">Email:</label>
<input type="text" name="email" id="email" maxlength="120" required/>
<label for="message">Message:</label><br />
<textarea name="message" rows="20" cols="20" id="message" required></textarea>
<input type="submit" name="submit" value="Submit" class="submit-button" onsubmit="displayMessage()" />
And the code to send the email:
<?php
if($_POST["submit"]) {
// The message
$message=$_POST["message"];
$email=$_POST["email"];
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");
// Send
mail('myemail.co.uk', $email, $message);
$sent_mail = true;
}
?>
And finally:
<?php
if (isset($sent_mail)) {
echo 'Thank you. We will be in touch soon.';
}
?>
So when the email is sent, sent_mail is set to 'true' and therefore the thank you message should be echoed. But right now this isn't working. The email sends first but the thank you message doesn't show. I basically just need a thank you message to come up somewhere on the page when the submit button is pressed.
Any ideas?
Instead of isset use simply if
Like this
mail
function returns a boolean (true/false), so you can do like thisAlso, the structure of
mail
(the parameters) are to-address, subject, message. Which means that your current subject is the email-address, I'm not sure if this is what you intended?Use
And finally:
You are assigning Boolean to $sent_mail and you set it to True.