flash/php contact form

Get help on web editors (Frontpage, Dreamweaver) and web languages (HTML, ASP, PHP).
Post Reply
Buddha
Registered User
Posts: 62
Joined: 02 Nov 2004, 02:00

flash/php contact form

Post by Buddha »

Hey there peeps!

I am building a flash contact form for a site and then i want to use the mail() php class to send the mail.

This is the actionscript for the send button says:

Code: Select all

on (release) {
var myVars:LoadVars = new LoadVars();
myVars.firstName = firstName.text;
myVars.lastName = lastName.text;
myVars.emailAddress = emailAddress.text;
myVars.region = region.label;
myVars.plzDirect = plzDirect.label;
myVars.theMessage = theMessage.text;
myVars.httpLink = httpLink.text;
myVars.tcAccept = tcAccept.selected;
myVars.sendAndLoad("form.php", myVars,"POST");
gotoAndStop (2);
}
then the form.php is this:

Code: Select all

<?php

    $firstName = $_POST['firstName'];
    $lastName = $_POST['lastName'];
    $emailAddress = $_POST['emailAddress'];
	$region = $_POST['region'];
	$plzDirect = $_POST['plzDirect'];
	$theMessage = $_POST['theMessage'];
	$httpLink = $_POST['httpLink'];
	
	
     // Email will go here
    $recipient = 'ruark@rubiksroom.com';

    //subject duh!
    $subject = 'New form submission from TRR site';

     // headers & content
    $headers = 'Content-type: text/html; charset=iso-8859-1';

    $content = "<html><head><title>Contact Details</title></head><body><br />";
    $content .= "First Name: <b>" . $firstName . "</b><br />";
    $content .= "Last Name: <b>" . $lastName . "</b><br />";
    $content .= "Email: <b>" . $emailAddress . "</b><br />";
    $content .= "Dept: <b>" . $plzDirect . "</b><br /><hr /><br />";
    $content .= $theMessage . "<br>";
    $content .= $httpLink;	
    $content .= "<br /></body>";


    // The mail() function allows you to send mail.
    mail($recipient,$subject,$content,$headers);
?>

any ideas what the mail doesnt get sent :P
GreyWolf
Registered User
Posts: 4754
Joined: 06 Aug 2003, 02:00
Processor: PHENOM II 945
Motherboard: Asus M4A78
Graphics card: HIS ICEQ 4850 1GB
Memory: 4GB CORSAIR XMS II 1066
Location: , location, location!

Re: flash/php contact form

Post by GreyWolf »

I have had a number of issues with php mailing.

1. Does the server support PHP?
2. Have you tried with different e-mail addresses?

try those.
"Every normal man must be tempted at times to spit on his hands, hoist that black flag, and begin slitting throats."
- H. L. Mancken
po10cy
Registered User
Posts: 7160
Joined: 29 Jun 2004, 02:00
Location: Cape Town
Contact:

Re: flash/php contact form

Post by po10cy »

firstly, are you sure you have form.php in the same folder as the flash file?
when in doubt, paddle out... ;)
Buddha
Registered User
Posts: 62
Joined: 02 Nov 2004, 02:00

Re: flash/php contact form

Post by Buddha »

hehe Thanks forthe replies guys,

Yeah the server is running php and the files are all in the right locations :P

mmm i could attach the fla/.php if you want?
maxxis
Moderator Emeritus
Posts: 8307
Joined: 30 Jun 2004, 02:00
Location: ( . Y . )
Contact:

Re: flash/php contact form

Post by maxxis »

Problem is most likely with flash not sending the vars correctly to the php file

Make sure of the following.

The input fields in flash need to have the correct instance names. The instance name will be used as the vars content.

In the actionscript use the following and remove the function from the button. Assign the instance name send_button to the button. Add the code to the frame the button resides on.

Code: Select all


send_button.onRelease = submit;

w_message.onSetFocus = function(){w_message.text = ""};
w_name.onSetFocus = function(){w_name.text = ""};
w_number.onSetFocus = function(){w_number.text = ""};
w_email.onSetFocus = function(){w_email.text = ""};

function submit()
{
	if( w_message.text == "" || w_name.text == "" ||
		w_number.text == "" || w_email.text == "" )
	{
		message_status.text = "Please complete all the fields";
	}
	else if( w_email.text.indexOf('@') < 2 || w_email.text.indexOf('.') < 0 )
	{
		message_status.text = "Email address incorrect.";
	}
	else
	{
		//define variables
		


message = w_message.text;
name = w_name.text;
cellnumber = w_number.text;
email = w_email.text;
		
		
		
		
		loadVariables("send_mail.php", this, "POST");

message_status.text = "Busy...";

		this.onData = function(){
			for(var a in this) trace([a,this[a]])

				if(this.output=='sent'){
			// in case of success

			message_status.text = "Thank you";
		} else if(this.output=='Unable to send.'){
			//	else

			message_status.text = "error1";
		} else if(this.output=='error2'){

			message_status.text = "Critical error.";

		}

	}
}
}

Be sure to create a dynamic text field with the instance name message_status. This will be used to get feedback from the php file.

Now for the PHP.

Code: Select all


<?php


$contact_subject = 'Contact from website';

$message = $_POST['message'];
$name = $_POST['name'];
$cellnumber = $_POST['cellnumber'];
$email = $_POST['email'];


if($email)
{
	$sender = $email;
	$receiver = "you@yourdomain.co.za";
	$client_ip = $_SERVER['REMOTE_ADDR'];
	$email_body = "Name: $name \nEmail: $sender \nSubject: $contact_subject \nMessage: $boodskap \nCell number: $cellnumber \nEmail: $email \n";		
	$extra = "From: $sender\r\n" . "Reply-To: $sender \r\n" . "X-Mailer: PHP/" . phpversion();

	if(@mail( $receiver, "Web Contact - $contact_subject", $email_body, $extra) ) 
	{
		echo "output=sent";
	}
	else
	{
		echo "output=error1";
	}
}
else
	{
		echo "output=error2";
	}
?> 
The PHP will only send if the contact details are valid and all the form fields are completed. Flash will check it first and then the PHP will handle it.

The if statement in the PHP will send the mail to you and return the success message if it worked or the error message if not

The critical error will be returned if the form variables did not pass from flash.

Test the mailer function first by creating a HTML file with a form that posts to the processor page.

Hope this helps.
Buddha
Registered User
Posts: 62
Joined: 02 Nov 2004, 02:00

Re: flash/php contact form

Post by Buddha »

Thanks for the replies guys,

I managed to get it working last night. It was how the variables were being sent to the php file.

Now that that is sorted im getting my emails :P

Quick question tho. When referencing a dropdown box in flash, how do you reference the selected option?

ie for a text field its: firstName = firstName.text; but for a dropdown? If you use region = region.labels; it will list ALL the options in the variable.

Thanks again for the help :P
Buddha
Registered User
Posts: 62
Joined: 02 Nov 2004, 02:00

Re: flash/php contact form

Post by Buddha »

the drop down box they way to reference it is:

dropdownname.selectedItem.label;

:)

BTW does any1 know how to do flash uploads? Ie so that i can extend this form to allow the user to upload a file with it? (and then that file being emailed with to the receiver?)
GreyWolf
Registered User
Posts: 4754
Joined: 06 Aug 2003, 02:00
Processor: PHENOM II 945
Motherboard: Asus M4A78
Graphics card: HIS ICEQ 4850 1GB
Memory: 4GB CORSAIR XMS II 1066
Location: , location, location!

Re: flash/php contact form

Post by GreyWolf »

sorry man. I have not done that yet.

check out: www.flashkit.com and www.tutorialized.com
"Every normal man must be tempted at times to spit on his hands, hoist that black flag, and begin slitting throats."
- H. L. Mancken
Post Reply