i have this condition in my controller, but am wondering why the javascript alert doesn’t fire up even if the mail was sent successfully?
if(mail($to,$sub,$body,$headers)){
echo '<script>alert("Thank you for your enquiry.\nWe will get back to you soon\n");</script>';
$this->redirect(Yii::app()->homeUrl);
}
it just redirects to the homeUrl and skips the alert pop up box, why?
You can achieve this by putting the redirection in javascript as PHP redirects before the javascript is even sent to the browser if you want to show the alert before redirection
A flash messages as already mentioned by Adler is a good option so you can get the message on the redirected page (in case it is not critical to show the alert before redirection)