• fsockopen发送邮件


    public function requestByFsockopen($url,$post_data=array()){
    $url_array = parse_url($url);
    $hostname = $url_array['host'];
    $port = isset($url_array['port'])? $url_array['port'] : 80;
    $requestPath = $url_array['path'] ."?". $url_array['query'];
    $fp = fsockopen($hostname, $port, $errno, $errstr, 10);
    if (!$fp) {
    echo "$errstr ($errno)";
    return false;
    }
    $method = "GET";
    if(!empty($post_data)){
    $method = "POST";
    }
    $header = "$method $requestPath HTTP/1.1 ";
    $header.="Host: $hostname ";
    if(!empty($post_data)){
    $_post = strval(NULL);
    foreach($post_data as $k => $v){
    $_post[]= $k."=".urlencode($v);//必须做url转码以防模拟post提交的数据中有&符而导致post参数键值对紊乱
    }
    $_post = implode('&', $_post);
    $header .= "Content-Type: application/x-www-form-urlencoded ";//POST数据
    $header .= "Content-Length: ". strlen($_post) ." ";//POST数据的长度
    $header.="Connection: Close ";//长连接关闭
    $header .= $_post; //传递POST数据
    }else{
    $header.="Connection: Close ";//长连接关闭
    }
    fwrite($fp, $header);
    //-----------------调试代码区间-----------------
    /*$html = '';
    while (!feof($fp)) {
    $html.=fgets($fp);
    }
    echo $html;*/
    //-----------------调试代码区间-----------------
    fclose($fp);
    }
  • 相关阅读:
    分层领域模型
    JAVA集合Set 交集、差集、并集
    http状态码301和302详解及区别
    设计模式(16) 命令模式
    设计模式(15) 解释器模式
    设计模式(14) 模板方法模式
    设计模式(13) 职责链模式
    设计模式(12) 代理模式
    设计模式(11) 享元模式
    设计模式(10) 外观模式
  • 原文地址:https://www.cnblogs.com/zxqblogrecord/p/8579189.html
Copyright © 2020-2023  润新知