You don’t want (though you could if you want to do it a different way) to redirect if the message was sent properly, simply just show a success message to the screen.
Here’s my contact page and I commented where I setup and display the message in the code:
[php]<?php
require_once DIR . ‘/vendor/autoload.php’;
require_once ‘lib/includes/utilities.inc.php’;
use website_project\email\EmailData as Email;
use website_project\email\Contact as SendForm;
$submit = filter_input(INPUT_POST, ‘submit’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
if (isset($submit) && $submit === ‘submit’) {
$first_name = filter_input(INPUT_POST, ‘first_name’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$last_name = filter_input(INPUT_POST, ‘last_name’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$name = $first_name . ’ ’ . $last_name;
$email = filter_input(INPUT_POST, ‘email’, FILTER_SANITIZE_EMAIL);
$message = filter_input(INPUT_POST, ‘comment’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$topic = filter_input(INPUT_POST, ‘reason’, FILTER_SANITIZE_SPECIAL_CHARS);
/* Spambot check this uses a hidden Captcha technique */
$spambot = filter_input(INPUT_POST, 'subject', FILTER_SANITIZE_SPECIAL_CHARS);
$send = new SendForm(new Email($name, $email, $topic, $message, $spambot));
if (!$send->sendMail()) {
if (!$send->getName()) {
$nameError = $send->getNameError();
} else {
$displayName = $send->getName();
}
if (!$send->getEmail()) {
$emailError = $send->getEmailError();
} else {
$displayEmail = $send->getEmail();
}
if (!$send->getMessage()) {
$messageError = $send->getMessageError();
} else {
$displayMessage = $send->getMessage();
}
} else {
$success = 'Email successfully sent!'; // Set the success message if message was sent correctly:
}
}
require_once ‘lib/includes/header.inc.php’;
?>
Contact Form
First Name
Last Name
Email Address
Leave blank
comment
pricing
order info
<label class="textareaLabel" for="message">Message</label>
<textarea id="message" name="comment" placeholder="Enter message here..."></textarea>
<!-- Display the success message if email was sent -->
<?php echo isset($success) ?'<label>' . $success . '</label>': NULL; ?>
<input type="submit" name="submit" value="submit">
</fieldset>
</form>
<article class="span6 bg-color">
<div class="contact-info-block">
<h3>Contact Details</h3>
<ul class="contact-info">
<li class="phone"><a href="tel:1-734-748-7661">(734) 748-7661</a></li>
<li class="mail"><a href="mailto:[email protected]">[email protected]</a></li>
<li class="twitter"><a href="http://twitter.com/intent/tweet?screen_name=strider64">[member=57087]Strider64[/member]</a></li>
</ul>
</div>
</article>
<?php
require_once 'lib/includes/footer.inc.php';
[/php]
You can see a working example on my website contact page - see signature below.
HTH John
P.S. if you want to redirect to a different page I would look into using sessions, but I try to do the Keep It Simple Stupid (KISS) method whenever I can. ;D
P.P.S. BTW I do use PHPMailer though I don’t show it being used here, for I have it in one of my classes that I use here. I recommend using a third party mailer for it makes life so much simpler when it comes to coding.