2 Replies Latest reply on Feb 3, 2011 1:59 AM by otisme

    Email with Flex 4 and PHP




      I'm running into some problems attempting to convert flex 3 email tutorial file to flex 4 fx and spark code. Is there a tutorial out there that does email with flex4 and php?





        • 2. Re: Email with Flex 4 and PHP
          otisme Level 1

          Hello Ivan,


          Thanks for your email, I'm building out a small website at

          http://www.cbweb.net at the moment and the contact form can be tested

          there. I've left a comment as otisme on your url below, here's the



          ****************************************************************************************** *************



          The best tutorial for building a simple contact form was one I found here:





          But above is built in Flex 3. I needed one for Flex 4, so I've updated

          the code to support Flex 4 fx type layout and code, here it is, works


          and extremely fast




          <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"


                     xmlns:mx="library://ns.adobe.com/flex/mx" >



                    <!-- Place non-visual elements (e.g., services, value objects) here -->



                    <mx:HTTPService id="emailService" url="php/mail.php" method="POST"

          resultFormat="xml" result="emailResult()" useProxy="false"/>


                    <mx:EmailValidator id="mailValidator"


                                           source="" property="text"


                                           requiredFieldError="Enter your email" required="true" />


                    <mx:StringValidator id="nameValidator"


                                             source="" property="text"


                                             requiredFieldError="Enter your name" required="true"/>


                    <mx:StringValidator id="emailValidator"


                                             source="" property="text"


                                             requiredFieldError="Enter your message" required="true"/>







                    <fx:Style  source="css/style.css">

                         @namespace s "library://ns.adobe.com/flex/spark";

                         @namespace mx "library://ns.adobe.com/flex/mx";










                              import mx.events.ValidationResultEvent;


                              import mx.controls.Alert;


                              private function sendMail():void{


                              var _senderName:String = senderName.text;


                              var _senderEmail:String = senderEmail.text;


                              var _emailMessage:String = emailMessage.text;


                              var _emailSubject:String = emailSubject.text;


                              var evValidMail:ValidationResultEvent = mailValidator.validate();


                              var evValidName:ValidationResultEvent = nameValidator.validate();


                              var evValidMessage : ValidationResultEvent = mailValidator.validate();




                              if (evValidMail.type == ValidationResultEvent.VALID


                              && evValidName.type == ValidationResultEvent.VALID


                              && evValidMessage.type == ValidationResultEvent.VALID){


                              emailService.send({senderName: _senderName,

          senderEmail:_senderEmail, emailSubject:_emailSubject, emailMessage:







                              resultLabel.text="There are Form errors";


                              resultLabel.setStyle("styleName", "invalid");






                              private function emailResult():void{


                              Alert.show("Thank you for your submission ");






                              private function clearForm():void{


















                    <mx:Panel height="401" width="400" layout="absolute" title="Contact

          us" backgroundColor="#050505">


                         <mx:Form x="9" y="10" width="360" backgroundColor="#BCB5B5">


                              <mx:FormItem label="Name :" contentBackgroundColor="#1E1C1C">


                                   <mx:TextInput id="senderName" contentBackgroundColor="#DEDEDE"/>




                              <mx:FormItem label="Email :">


                                   <mx:TextInput id="senderEmail" contentBackgroundColor="#DEDEDE"/>




                              <mx:FormItem label="Subject :">


                                   <mx:TextInput id="emailSubject" contentBackgroundColor="#DEDEDE"/>




                              <mx:FormItem label="Message :">


                                   <mx:TextArea id="emailMessage" height="132" width="213"







                         <mx:Button label="Send" click="sendMail()" x="138" y="274"/>


                         <mx:Label id="resultLabel" x="212" y="276"/>










          and the php file you point above at should have:




             $senderName = $_POST['senderName'];


             $senderEmail =  $_POST['senderEmail'];


             $sendToEmail = "colmbrazel@gmail.com";


             $subject = $_POST['emailSubject'];


             $emailMessage = $_POST['emailMessage'];


             $recipient = "$sendToEmail";


             $headers = "From: $senderEmail ";


             $message = "From: $senderName, \nEmail Address:

          $senderEmail\nSubject: $subject\n\nMessage: $emailMessage";


             $message = stripslashes($message);


             mail($recipient, $subject, $message, $headers)





          and you can create your own style.css to suit above