Well, there's really no need to actually "display" the php page at all. The attached zip file contains a form contact page I use at work. It's a little more complex than your basic form but contains all the necessary elements to a good working form using a php mailer. (I've altered this a bit from the original, but credit to UNFLUX who designed the original page)
contactForm.zip
(130.97 KiB) Downloaded 928 times
Includes FLA and php scrip for generalContact.
When you open the FLA in your actions panel, in the left pane expand formGeneral and take a look at the submit button code.
on (release) {
if (name eq "" or email eq "" or message eq "") {
error.gotoAndPlay("error");
} else {
loadVariablesNum("contactGeneral.php", 0, "POST");
error.gotoAndPlay("sent");
name = "";
company = "";
phone = "";
email = "";
message = "";
}
}
- on (release) {
- if (name eq "" or email eq "" or message eq "") {
- error.gotoAndPlay("error");
- } else {
- loadVariablesNum("contactGeneral.php", 0, "POST");
- error.gotoAndPlay("sent");
- name = "";
- company = "";
- phone = "";
- email = "";
- message = "";
- }
- }
-
Lets break that down. When we release the button the first thing we do is check to see if all required fields are completed. It's always a good idea to require at least some if not all fields to avoid getting empty emails.
if (name eq "" or email eq "" or message eq "")
*note - name, company, phone, email, and message are the variable names given to the respective text input fields. The code above then uses those variables to pass to your php script.
If any of the required fields is empty we send the user an error message
error.gotoAndPlay("error");
the first "error" in the code above is the instance name of a movie clip called error which basically contains two messages. One is a sent successfully message, the other is an error message telling them to complete all required fields. In the attached FLA you can see the error movie clip by selecting it from the library to edit.
The second "error" in parenthesis is the label assigned to the error message.
If all required fields are met, then we're going to load contactGeneral.php which is my mail script
loadVariablesNum("contactGeneral.php", 0, "POST");
Here we use loadVariablesNum instead of getUrl which simply loads the Variables into the php script and we do this by the POST method vs the GET method.
The variables we are loading are
name = "";
company = "";
phone = "";
email = "";
message = "";
- name = "";
- company = "";
- phone = "";
- email = "";
- message = "";
Essentially it's identical to your fields except I have a company field in mine.
Then to give them a success message we send them back to the "error" movieClip at the label "sent" which displays the success message, which in your case is where you could have:
"Thank you
We have recieved your email and we will get back to you shortly."
error.gotoAndPlay("sent");
The included php file, now is pretty self explanatory:
<?
if (isset($HTTP_POST_VARS)) {
$name = $HTTP_POST_VARS["name"];
$company = $HTTP_POST_VARS["company"];
$phone = $HTTP_POST_VARS["phone"];
$email = $HTTP_POST_VARS["email"];
$message = $HTTP_POST_VARS["message"];
}
$to = "generalContact@alaron-nuclear.com";
$from = "webmaster@alaron-nuclear.com";
$subject = "Alaron General Contact Form";
$msg .= "Senders Name: " ."$name\n\n";
$msg .= "Company: " ."$company\n\n";
$msg .= "Phone: " ."$phone\n\n";
$msg .= "Email: " ."$email\n\n";
$msg .= "Message: " ."$message\n\n";
$msg .= "This message was sent to you from Alaron-Nuclear Contact Request Form.\n\n";
$msg .= "Do not reply to this email directly.";
mail($to, $from, $subject, $msg, "From: Alaron Web Site\nReply-To: $email\n");
?>
- <?
-
- if (isset($HTTP_POST_VARS)) {
-
- $name = $HTTP_POST_VARS["name"];
- $company = $HTTP_POST_VARS["company"];
- $phone = $HTTP_POST_VARS["phone"];
- $email = $HTTP_POST_VARS["email"];
- $message = $HTTP_POST_VARS["message"];
- }
-
- $to = "generalContact@alaron-nuclear.com";
- $from = "webmaster@alaron-nuclear.com";
- $subject = "Alaron General Contact Form";
- $msg .= "Senders Name: " ."$name\n\n";
- $msg .= "Company: " ."$company\n\n";
- $msg .= "Phone: " ."$phone\n\n";
- $msg .= "Email: " ."$email\n\n";
- $msg .= "Message: " ."$message\n\n";
- $msg .= "This message was sent to you from Alaron-Nuclear Contact Request Form.\n\n";
- $msg .= "Do not reply to this email directly.";
-
- mail($to, $from, $subject, $msg, "From: Alaron Web Site\nReply-To: $email\n");
-
- ?>
Hope that helps and doesn't confuse you more.