flex发送邮件

flex借助php发送邮件,并附表单验证功能,表单如填写不正确,则邮件不能发送~~

mail.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp()" layout="absolute" fontSize="14">
<mx:Script>
 <![CDATA[
  import mx.events.ValidationResultEvent;
  import mx.controls.Alert;
  import mx.validators.Validator;
  private var myValidators:Array;

  private function initApp():void {
   myValidators = [valid1, valid2,valid3];
  }

  private function sendmail():void{
   
   var errors:Array = Validator.validateAll(myValidators);
   if (errors.length == 0) {
     //Alert.show("Looks valid to me.", "SUCCESS"); 
     mailit.send();
      Alert.show("发送成功","alert");
    }

   else{
     Alert.show("请正确填写表单","alert");
    }
   }
 ]]>
</mx:Script>
 <mx:HTTPService id="mailit" url="mail/sendmail.php" method="POST" useProxy="false">
  <mx:request xmlns="">
   <receipt>{receipt.text}</receipt><mailfrom>{mailfrom.text}</mailfrom><mailbody>{mailbody.text}</mailbody>
  </mx:request>
 </mx:HTTPService>
 <mx:Iris id="iris" target="{panel}"></mx:Iris>
 <mx:Panel id="panel" x="350" y="132" width="464" height="408" layout="absolute" creationCompleteEffect="iris">
  <mx:Label id="label1" text="收件人" x="35" y="91"/>
  <mx:TextInput id="receipt" text="" x="113" y="89" />
  <mx:Button id="button1" label="发送邮件"  x="25" y="321" click="sendmail()" />
  <mx:Label x="35" y="45" text="发件人"/>
  <mx:TextInput x="113" y="43" text="" id="mailfrom" />
  <mx:TextArea x="113.5" y="133" width="306" height="175" text="" id="mailbody" />
  <mx:Label x="35" y="134" text="邮件内容"/>
  <mx:Label x="178" y="10" text="Flex发送邮件" width="105" fontSize="16" />
 </mx:Panel>
<mx:EmailValidator source="{receipt}" id="valid1" property="text" trigger="{button1}" triggerEvent="click"/>
<!--  valid="Alert.show('Email格式正确!');" -->
<mx:StringValidator id="valid2" source="{mailfrom}" property="text"
        tooShortError="字符串太短了,请输入最少3个字符. "
        tooLongError="字符串太长了,请输入最长20个字符. "
        minLength="3" maxLength="20"
        trigger="{button1}" triggerEvent="click"
        />  <!-- valid="Alert.show('字符串格式正确!');" -->
<mx:StringValidator id="valid3" source="{mailbody}" property="text"
        tooShortError="字符串太短了,请输入最少10个字符. "
        tooLongError="字符串太长了,请输入最长200个字符. "
        minLength="10" maxLength="200"
        trigger="{button1}" triggerEvent="click"
        />  <!-- valid="Alert.show('字符串格式正确!');" -->
</mx:Application>

    A+
发布日期:2009年05月14日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: