In that case you need to echo the JavaScript on the final page as currently (as suggested above) the page is redirecting before the JavaScript is seen by the user.
You need to send back a message to contactus.php which allows you to tell the difference between a successful and failed message, you can do this with a query string (?name=value).
PHP Code:
$qry = "insert into contactus(name,email,subject,message) values('$name','$email','$subject','$message')";
$result=mysql_query($qry);
if($result){
header('Location: contactus.php?status=sent');
}else{
header('Location: contactus.php?status=fail');
}
Add this to the top of contactus.php
PHP Code:
if(!empty($_GET['status'])){
$status = $_GET['status'];
echo '<script type="text/javascript">';
echo 'alert("';
echo ($status == sent) ? 'Your message was successfully sent.':'Could\'nt send your message.';
echo '");';
echo '</script>';
}
Bookmarks