PHP利用宝塔邮局发送邮件

    //发送邮件 宝塔邮件系统发送
    protected function send_mail()
  {
$postdata = [ 'mail_from' => '创建的用户', 'password' => '创建的用户密码', 'mail_to' => $this->toEmail,//发送给谁 'subject' => 'Verification', //标题 'content' => $this->bodyEmail, //邮件内容 ]; $url = 'http://ip地址:8887/mail_sys/send_mail_http.json';//宝塔的地址 $res = $this->curl_request($url,$postdata); $res = json_decode($res,true); if($res['status']){ return true; }else{ return false; } }
  
  //curl请求
protected function curl_request($url,$post='',$cookie='', $returnCookie=0)
  {
$curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)'); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_AUTOREFERER, 1); curl_setopt($curl, CURLOPT_REFERER, "http://XXX"); if($post) { curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post)); } if($cookie) { curl_setopt($curl, CURLOPT_COOKIE, $cookie); } curl_setopt($curl, CURLOPT_HEADER, $returnCookie); curl_setopt($curl, CURLOPT_TIMEOUT, 10); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($curl); if (curl_errno($curl)) { return curl_error($curl); } curl_close($curl); if($returnCookie){ list($header, $body) = explode("\r\n\r\n", $data, 2); preg_match_all("/Set\-Cookie:([^;]*);/", $header, $matches); $info['cookie'] = substr($matches[1][0], 1); $info['content'] = $body; return $info; }else{ return $data; } }

 

posted @ 2022-01-17 14:55  贱贱丶  阅读(661)  评论(0编辑  收藏  举报