返回顶部

收藏

一个简单的php email类

更多
import mx.events.EventDispatcher;
import mx.utils.Delegate;

class Emailer {

    // required for EventDispatcher:
    public var addEventListener:Function;
    public var removeEventListener:Function;
    private var dispatchEvent:Function;

    // use to communicate with php script
    private var _lv:LoadVars;
    // holds address of sender
    private var _sentFrom:String;

    // constructor
    public function Emailer() {    
        EventDispatcher.initialize(this);
        _lv = new LoadVars();
    }

    // 
    private function dataReceived(dataxfer_ok:Boolean):Void {
        // if some problem with loadVars transfer, pass back error=2
        if (!dataxfer_ok) dispatchEvent({target:this, type:'mailSent', errorFlag:2});
        // otherwise pass back error code returned from script
        else dispatchEvent({target:this, type:'mailSent', errorFlag:Number(_lv["faultCode"])});
    }

     // Use loadvars object to send data (set to call dataReceived when script returns data)
    public function sendEmail(sub:String, fn:String, fe:String, msg:String, rep:String):Void {
        // if user already sent from this address, show error msg
        if (_sentFrom == fe) dataReceived(false);
        // otherwise set up and send
        else {
            _sentFrom = fe;
            // specify function to handle results, make scope = Emailer
            _lv.onLoad = Delegate.create(this, dataReceived);
            // set up properties of lv to items to be POSTed
            _lv.subject = sub;
            _lv.name = fn;
            _lv.email = fe;
            _lv.message = msg;
            _lv.reply = rep;
            // call script
            _lv.sendAndLoad("sendemail.php", _lv, "POST");
        }
    }
} 

标签:email,邮件发送,php

收藏

0人收藏

支持

0

反对

0

相关聚客文章
  1. Christopher Pitt 发表 2016-04-22 16:00:00 What is SparkPost?
  2. Christopher Pitt 发表 2016-04-22 16:00:00 What is SparkPost?
  3. cmpan 发表 2012-10-23 06:36:51 给ecshop添加可选择多语言
  4. kcloze 发表 2016-12-02 07:36:06 把扩展从php5升级到php7(翻译)
  5. colinhu 发表 2012-12-02 08:47:07 LAMP架构相关书籍介绍
  6. Christopher Pitt 发表 2017-01-13 18:00:38 Home-Made Twitter and Gmail Notifications with PHP
  7. 丸子 发表 2012-06-28 09:50:50 phpBB < 3.0.10 附件物理路径泄露
  8. sunny5156 发表 2017-02-09 07:45:01 php调用科大讯飞Java SDK
  9. linuxphp@qq.com(kemi 发表 2012-11-17 21:49:00 Windows系统VS编译PHP源码5.3
  10. 技术奇客 发表 2016-05-10 04:24:48 Hacked By GeNErAL
  11. leo 发表 2013-03-31 14:44:15 PHP生成长微博
  12. xirruiqiang 发表 2017-02-22 15:02:41 PHP core整合加密库Libsodium

发表评论