PHPパッケージ送信メール類!

2146 ワード


/**
 *       
 *       Crul 
 *      :1000  /   。           。
 *           ,        15  。
 *         65   (        65 )。  
 */ 
class SMS{
    private $curl=null;
    private $uid=null;//  id
    private $key=null;//  key
    private $error=null;//    
    private $server='http://it266.sinaapp.com/sendsms.php';//   url
    
    public function __construct($uid,$key){
        $this->uid=$uid;
        $this->key=$key;
        
        $this->curl = curl_init($this->server);
        curl_setopt($this->curl, CURLOPT_HEADER, 0 ); //   HTTP 
        curl_setopt($this->curl,CURLOPT_RETURNTRANSFER, 1);//       
        curl_setopt($this->curl,CURLOPT_POST,true); // post    
    }
    
    public function __get($name){
        if($name=='error'){
            return $this->error;
        }
    }

    public function setServer($server){
        $this->server=$server;
    }
    
    public function getError(){
        return $this->error;
    }
    
    //    
    //    true,    false
    public function send($mobile,$content){
        $para=array(
            'uid'=>$this->uid,
            'key'=>$this->key,
            
            'mobile'=>$mobile,
            'content'=>$content,
        );
        
        curl_setopt($this->curl,CURLOPT_POSTFIELDS,$para);// post    
        $responseText = curl_exec($this->curl);
        //var_dump( curl_error($this->curl) ); 
        
        if($responseText=='1'){
            return true;
        }
        $this->error=$responseText;
        return false;
    }
    
    public function __destruct(){
        curl_close($this->curl);
    }
    
}

呼び出し例:
header("Content-Type:text/html;charset=utf-8");
$sms_id = 1;//   ID,      user_id
$sms_key= '8e14eeec65bc8e8b3d2c';//   KEY,      user_key
$sms=new  SMS($sms_id,$sms_key); //    : 
$result=$sms->send($phone = '18858287938',$content = '   ,   ?');
echo $result ? '          ' : '      。'.$sms->getError();