返回顶部

收藏

一个简单的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. Athurg Gooth 发表 2013-07-09 07:47:35 header无法跳转的问题——坑爹的PHP
  4. jakehu 发表 2014-10-30 07:33:33 Php利用正则表达式提取内容中的所有图片(Img)或第一张图片(Img)
  5. saymoon 发表 2012-09-16 09:01:14 linux下nginx多版本php共存
  6. luanhailiang 发表 2014-07-31 10:24:20 centos php cr
  7. minyifei 发表 2015-05-14 01:32:20 PHP远程下载文件到本地的函数(转)
  8. liudixing 发表 2015-01-26 13:45:47 修改WordPress中the_excerpt()函数截取中文的长度
  9. 小李刀刀 发表 2015-02-22 12:42:07 [译]Laravel 5.0 之事件调度程序 (定时任务)
  10. admin 发表 2015-02-13 07:18:50 Laravel
  11. 博主 发表 2015-01-26 02:46:07 PHP escape unescape 实现
  12. admin 发表 2015-04-28 01:30:27 多维数组排序

发表评论