sandyzelaya Posted September 12, 2007 Share Posted September 12, 2007 I've justed learning some php and actionscript but the email function in php is way out of my league. I need help making a php email script that will process POST data from a flash form and send it to my email box. Upon the clipping event the flash form will automatically move to a next frame (but that code has been taken care of ). My variables are as follows: name email city country artists event otherinfo <?php $name=$_POST['name']; $email=$_POST['email']; $subject=$_POST['event']; $message=$_POST['message']; $name=trim($name); $email=trim($email); $subject=StripSlashes($subject); $message=StripSlashes($message); $toaddress='myemail@tesingphp.com'; mail($toaddress,$subject,$message,"From: $name <$email>"); $name=''; $email=''; $subject=''; $message=''; echo "response=passed"; ?> This is what i think i've managed so far. I've also attached a copy of my flash FLA file just in case this is of any help. Thanks in advance. Sandy Zelaya [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/69069-email-form-help/ Share on other sites More sharing options...
darkfreaks Posted September 12, 2007 Share Posted September 12, 2007 just curious but why do you have <?php $name=''; $email=''; $subject=''; $message='';?> in your code? Quote Link to comment https://forums.phpfreaks.com/topic/69069-email-form-help/#findComment-347194 Share on other sites More sharing options...
sandyzelaya Posted September 12, 2007 Author Share Posted September 12, 2007 i've just started learning php.... so im not really sure why it's there... i guess i found some logic to it at some momment... :-\ Quote Link to comment https://forums.phpfreaks.com/topic/69069-email-form-help/#findComment-347198 Share on other sites More sharing options...
darkfreaks Posted September 12, 2007 Share Posted September 12, 2007 <?php $submit=$_POST['submit']; $name=$_POST['name']; $email=$_POST['email']; $subject=$_POST['event']; $message=$_POST['message']; $name=trim($name); $email=trim($email); $subject=StripSlashes($subject); $message=StripSlashes($message); $toaddress='myemail@tesingphp.com'; if(!$_POST[submit]){echo "Sorry but you have Not filled out The form"; } else { mail($toaddress,$subject,$message,"From: $name <$email>"); echo "response=passed";}?> Quote Link to comment https://forums.phpfreaks.com/topic/69069-email-form-help/#findComment-347203 Share on other sites More sharing options...
sandyzelaya Posted September 12, 2007 Author Share Posted September 12, 2007 this script should be able to mail me all the variables? Quote Link to comment https://forums.phpfreaks.com/topic/69069-email-form-help/#findComment-347206 Share on other sites More sharing options...
darkfreaks Posted September 12, 2007 Share Posted September 12, 2007 test it out but it tells the PHP part if submit equals false to not send the form and echo the error otherwise to mail it and echo. Quote Link to comment https://forums.phpfreaks.com/topic/69069-email-form-help/#findComment-347207 Share on other sites More sharing options...
sandyzelaya Posted September 12, 2007 Author Share Posted September 12, 2007 it wont work :-\ at least in the intitial script something was emailed to my account in some way. i wont be needing the false echo because actionscript took care of that. still i'm worried the variables wont be emailed properlly... Quote Link to comment https://forums.phpfreaks.com/topic/69069-email-form-help/#findComment-347217 Share on other sites More sharing options...
darkfreaks Posted September 12, 2007 Share Posted September 12, 2007 well what exactly is the problem? Quote Link to comment https://forums.phpfreaks.com/topic/69069-email-form-help/#findComment-347221 Share on other sites More sharing options...
sandyzelaya Posted September 12, 2007 Author Share Posted September 12, 2007 it wont process the form at all. i wont even get a email anymore Quote Link to comment https://forums.phpfreaks.com/topic/69069-email-form-help/#findComment-347227 Share on other sites More sharing options...
darkfreaks Posted September 12, 2007 Share Posted September 12, 2007 <?php $headers = "From: " . $_POST["name"]; $headers .= "<" . $_POST["email"] . ">\r\n"; $headers .= "Reply-To: " . $_POST["email"] . "\r\n"; $headers .= "Return-Path: " . $_POST["email"]; mail($toaddress,$subject,$message,$headers); ?> Quote Link to comment https://forums.phpfreaks.com/topic/69069-email-form-help/#findComment-347233 Share on other sites More sharing options...
plutomed Posted September 12, 2007 Share Posted September 12, 2007 Make sure you are getting the variables from the flash file by echoing each variable. Quote Link to comment https://forums.phpfreaks.com/topic/69069-email-form-help/#findComment-347255 Share on other sites More sharing options...
sandyzelaya Posted September 12, 2007 Author Share Posted September 12, 2007 echoing??? how is this done? Quote Link to comment https://forums.phpfreaks.com/topic/69069-email-form-help/#findComment-347282 Share on other sites More sharing options...
darkfreaks Posted September 12, 2007 Share Posted September 12, 2007 <?php echo ($_POST[variable]);?> Quote Link to comment https://forums.phpfreaks.com/topic/69069-email-form-help/#findComment-347287 Share on other sites More sharing options...
sandyzelaya Posted September 12, 2007 Author Share Posted September 12, 2007 OK i've come up with this... its probally wrong... I still have a feeling only the name, email, and event variables are being used. Are the rest being emailed to me too? <?php $submit=$_POST['submit']; $name=$_POST['name']; $email=$_POST['email']; $subject=$_POST['event']; //shouln't my missing variables go here somewhere $message=$_POST['message']; $name=trim($name); $email=trim($email); $subject=StripSlashes($subject); $message=StripSlashes($message); $toaddress='myemail@tesingphp.com'; $headers = "From: " . $_POST["name"]; $headers .= "<" . $_POST["email"] . ">\r\n"; $headers .= "Reply-To: " . $_POST["email"] . "\r\n"; $headers .= "Return-Path: " . $_POST["email"]; mail($toaddress,$subject,$message,$headers); echo ($_POST[name]); echo ($_POST[email]); echo ($_POST[city]); echo ($_POST[country]); echo ($_POST[artists]); echo ($_POST[event]); echo ($_POST[otherinfo]); ?> Quote Link to comment https://forums.phpfreaks.com/topic/69069-email-form-help/#findComment-347301 Share on other sites More sharing options...
darkfreaks Posted September 12, 2007 Share Posted September 12, 2007 tell me which variables are being echoed right and which variables dont echo. those that arent echoed prolly arent being passed through the action script. Quote Link to comment https://forums.phpfreaks.com/topic/69069-email-form-help/#findComment-347311 Share on other sites More sharing options...
sandyzelaya Posted September 12, 2007 Author Share Posted September 12, 2007 i know its probally a lot to ask but could you please take a look at the .FLA file and try to stir up a php file acordingly :-\ the websites already up and running but i cant get this to work... you can check it out if you like: rotatethis.net [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/69069-email-form-help/#findComment-347316 Share on other sites More sharing options...
darkfreaks Posted September 12, 2007 Share Posted September 12, 2007 Flash-Based Email Form Using PHP by senocular Introduction Here we will cover the process involved in making a very simple email form in Flash using PHP. Be aware that Flash alone is incapable of sending email. PHP, or some other server-side script like PHP, is needed to handle that operation. Put the two together, though, and you got yourself a great way for people to email you directly through your Flash-based web site. How it Works Because PHP is being used to send an email, Flash needs a way to communicate to PHP to let it know when to send an email and with what information. Flash relies on PHP to handle the email sending responsibility. When a Flash movie is ready to have an email sent, it needs to talk to a PHP script on the server so that script can then instruct the server to send the email with the information provided. A way Flash can send information to an external PHP page is through the loadVariables Actionscript command. This allows Flash to open a page on the server, like a PHP script, and send it specific information that allows you to control how that script behaves. In the case of this tutorial, to have a PHP script email information inputted in a Flash form. Flash sends the PHP page the information filled out in the form. The PHP script then inserts that information into a mail function which instructs the server to send an email with that information to the email address specified. Easy enough, right? Lets begin creating the Flash form. Steps to Create Form The Flash form consists of 2 basic parts. One part is the group of text fields that make up the form. These are actually contained within a movieclip aptly named "form." Secondly, you have the send button. This will be the button that activates the code that sends the form information to the PHP file. At that point, Flash's job is done. It's then up to the PHP script to make sure the email gets sent. Start off by making the appropriate form fields. Make sure these are input fields and not static or dynamic text fields Include as many as you want. Each will be sent to the PHP file where they can then be sorted. This example uses 3. Assign each text field a var value. This is NOT an instance name. The var field allows you to associate a variable with the given text field Because loadVariables is being used to transmit the information, this is needed to make the value of these text fields easily recognized as variables to that command. This example uses name, email, and body for field variable names. [ assign a var value for each text field ] Once you have created and named each field, select them all and create a new movieclip out of them. This will be the form movieclip. Give it the instance name form when you're done. [ all fields in a movieclip named form ] Next, create a button. This will serve as the send button. This will exist not within the form, but in the same place as the form. It's on this button that the loadVariables script will be added. That script is as follows: form.loadVariables("email.php", "POST"); This calls loadVariables through the form movieclip sending all variables saved in that movieclip to email.php using the POST method. Because all the text fields in form have variables associated with them, this effectively sends all information filled out in those fields to the email PHP page. From that PHP page, the sent information can be retrieved using each field's var name. One thing to be cautious of is that you need to make sure the movieclip you are using loadVariables with exists long enough for it to send its variables to the URL specified. Because this mailer has a thank you screen after sending an email, you'll need to wait until Flash does that before showing that screen and losing the form movieclip. You can tell when a movieclip has sent its variables out from its onClipEvent(data) event. This is event is called when the movieclip receives data from the server either confirming its variables have been sent or in the case where new variables are brought into Flash. We aren't bringing variables in, just sending out. But we do need to know when that's taken place. So on the form movieclip we can add the script that checks for that. When the event runs, we can then go to the next frame showing the thank you screen. onClipEvent(data){ _root.nextFrame(); } Steps in Scripting PHP Now we can write that PHP script, email.php, that really makes this happen. Luckily, it's not really all that difficult to write. Maybe not as easy as the previous Flash script, but not difficult nonetheless. The PHP all revolves around one function; the mail function. All you need to do is to grab the information sent from Flash and pass it in to this mail function in PHP to have that information sent to your email of choice. Create a PHP file if you haven't already. If you're not sure how, just make a text file. A PHP file is basically nothing more than a text file with a .php extension instead of .txt. To a server, though, a php file is seen not as text, but as a script for carrying out commands - commands like our email command. Using Dreamweaver or your text editor of choice, start writing your PHP script. This will consist of 3 basic parts. One will be a place for constant variables that will always remain the same. This will include things such as your email. Another is the capturing of those variables sent to the script from Flash - those filled out in the Flash form. Finally, that information is then setup in the third part, the call of the mail function. Part 1: Begin the file with a php tag and the setting up of constant variables. This includes your email and most likely a subject line as well. <?php $sendTo = "senocular@hotmail.com"; $subject = "My Flash site reply"; Part 2: Now you can start getting the variables that Flash sent. Since Flash sent the variables using post, we would use $_POST to get them into variables of our own. $_POST is a special global variable in a PHP script that contains all of the posted variables sent to that script as an associative array. Using brackets ([]) and a variable name, you can then retrieve those variables. For those variables sent by this particular example, you would obtain their value in PHP using $_POST["name"], $_POST["email"], and $_POST["message"]. $headers = "From: " . $_POST["name"]; $headers .= "<" . $_POST["email"] . ">\r\n"; $headers .= "Reply-To: " . $_POST["email"] . "\r\n"; $headers .= "Return-Path: " . $_POST["email"]; $message = $_POST["message"]; *Name and email here are assigned to a single variable, headers, because of how the mail function works... Part 3: Finally the mail function. This function is set up to take 3 to 5 different parameters. We're only concerned about 4: mail(recipient, subject, message, other headers); With our previous variable definitions, we can easily just plug and play to run this command in the final php script. Note that "from" and "reply-to" are not separate parameters within the mail call. These are part of the 4th parameter, additional headers, where information beyond the recipient, subject and email message go. With that, we can finish off the script with the following. mail($sendTo, $subject, $message, $headers); ?> Save as email.php and you're set. Putting it All Together All that remains now is uploading your published swf (with accompanying html) and PHP file to your server. Be sure you keep the PHP file in the same directory as your swf and html or your script may not be found when called from Flash. If you don't want it to be in that same directory, be sure you correctly reference the location of the PHP file in the loadVariables command used in Flash. Once uploaded, play your movie and send yourself a message! It'll be fun - and it will also test to make sure this actually works since, if you didn't already know, you can't test from your own computer's hard drive unless you have the proper configurations and PHP installed (which, more than likely, is not the case). It's ok though, since you don't need it on your personal computer, just your server. And if its working from there, then you should be in the clear. Quote Link to comment https://forums.phpfreaks.com/topic/69069-email-form-help/#findComment-347319 Share on other sites More sharing options...
sandyzelaya Posted September 12, 2007 Author Share Posted September 12, 2007 Ok... after following this tutorial (thanks for the find ) i cooked up this script <?php $sendTo = "rotatethis@zelaya.jazztel.es"; $subject = "Booking Post"; $headers = "From: " . $_POST["name"]; $headers .= "<" . $_POST["email"] . ">\r\n"; $headers .= "Reply-To: " . $_POST["email"] . "\r\n"; $headers .= "Return-Path: " . $_POST["email"]; $message = $_POST["event"]; $message = $_POST["artists"]; $message = $_POST["city"]; $message = $_POST["country"]; $message = $_POST["otherinfo"]; mail($sendTo, $subject, $message, $headers); ?> AND I GOT AN EMAIL!!! but... (theres always a but ) some variables are not showing up. Variables "event", "artists" , "city" and "country" are not in my message window. Apart from that (i know this is not php related) the code that i hooked up to the form movie: onClipEvent(data){ _root.nextFrame(); } wont seem to skip to the next frame... maybe an echo is missing? help? please..... Quote Link to comment https://forums.phpfreaks.com/topic/69069-email-form-help/#findComment-347331 Share on other sites More sharing options...
darkfreaks Posted September 12, 2007 Share Posted September 12, 2007 http://www.sephiroth.it/tutorials/flashPHP/email/page002.php see if this helps any Quote Link to comment https://forums.phpfreaks.com/topic/69069-email-form-help/#findComment-347337 Share on other sites More sharing options...
darkfreaks Posted September 12, 2007 Share Posted September 12, 2007 if not try <?php $variable= ($_POST['variable']); ?> Quote Link to comment https://forums.phpfreaks.com/topic/69069-email-form-help/#findComment-347349 Share on other sites More sharing options...
sandyzelaya Posted September 12, 2007 Author Share Posted September 12, 2007 aaaaaaaaaaaaaaaaaa!!!!!!!!! :'( ive been all day trying to get this to work and i cant. thanks for your help, its been greatly apreciated i tried taking everything step by step but with no luck... guess ill just have to keep learning... thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/69069-email-form-help/#findComment-347365 Share on other sites More sharing options...
darkfreaks Posted September 12, 2007 Share Posted September 12, 2007 can u attack the half working script? il ldownload flash and take alook. Quote Link to comment https://forums.phpfreaks.com/topic/69069-email-form-help/#findComment-347372 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.