Yes, I agree with Astonecipher. But, to add a bit to this subject…
Remember, once your user clicks on the submit button and you validate the data that is being sent,
normally, you would go to another page stating that the email was sent out. Or, you would just have
it show up on the current page as a notice near the top of the contact form. To change this into an alert,
you would have to incorporate Javascript to run CLIENT-SIDE. To do this, it is quite simple. Just pass a
value back to the page. I would use $_POST, not $_GET. “Gets” are shown on the address line and might
allow a hacker to alter them. You can pass a $_POST value by using PHP to insert it into your form so it
is passed back to the same page. Inside that form, just have it pop up the message using Javascript.
Or, even better, just use simple SESSION variables to pass if the email was sent or not back to contact form.
Should be quite easy to do. Just add a line after you send your mail to display the alert. I will explain it.
First, your contact page should be a PHP page, not HTML. This is so you can use PHP coding inside of it.
Next, the code for displaying the ALERT is simple Javascript (JS) code. Here is a working version…
[php]
[/php]
As you see, it is just a simple alert command in JS. Note that it should be at the bottom of your page and
it is set to execute once the entire page is loaded into the browser. (After all images and CSS is rendered!)
Since you really want this under program control, you do not want this JS routine to show up on the first
loading of the page. You want it only to show up after an email is sent out. Therefore, you would have to
set a field in your form so that you have control to show this routine or hide it if an email was not sent out.
(Such as if the user refreshes the page without pressing the submit button.
To handle that part, you would need to create a field in the form that you can alter using PHP. The JS code
above would have to be altered to see if that field contained a certain value or not. If it did, pop-up the JS
alert, if not, just skip it… Hope that makes sense!
You could also do this with hidden $_SESSION variables which I personally like to use. Since they can be
hidden from all users, it is more secure that way. And, you do not need to use hidden form fields. Either
way, you would use PHP to decide if the email was sent or not. If it did go out, add code to either set a
hidden form field to a value such as “Email-Sent” or whatever. Or, set a $_SESSION variable to the same.
If it did not go out set the hidden form field or session variable to “NOT-SENT” or whatever. Then, when
the page is loaded, these values are checked and the PHP would write out the JS script or NOT depending
on the value of the fields. The PHP code would be at the bottom of the page just before and it
would write or not the JS routine.
So, before I can drum up some sample code for you to test with, do you know what $_SESSION variables
are and are you comfortable in using them? If not, we would have to go the hidden field route. Either will
work, but sessions are much easier in my opinion. Let us know if you can solve this now or need further help. Good luck…