返回顶部

收藏

一个简单的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. 深1千米 发表 2015-02-06 04:04:06 PHP网站安全之强化服务器和php.ini
  4. 张映 发表 2015-02-09 03:53:48 windows server php exec 无法执行
  5. ErosSignum 发表 2015-02-03 05:47:28 Laravel-Genertators-翻译转
  6. 朱春来(Leslie Zhu) 发表 2015-02-23 16:00:00 学点PHP(5): Laravel、Homestead及Composer
  7. gouki 发表 2015-03-06 14:19:00 array_key_exists 和 isset
  8. Kerwin 发表 2015-03-13 05:27:07 win7下安装nginx+php+mysql教程
  9. AlloVince 发表 2014-12-28 16:19:15 使用xhprof进行线上PHP性能追踪及分析
  10. 天外飞仙 发表 2015-03-20 04:00:08 PHP程序员简历模板
  11. 张映 发表 2015-03-27 09:14:34 php 跨域 form提交 2种方法
  12. Reeze Xia 发表 2012-07-22 12:40:00 怎样获取PHP函数默认参数常量名

发表评论