| function send_mail($to, $subject = 'No subject', $body) { $loc_host = "Administrator"; $smtp_acc = "XXX@163.com"; $smtp_pass="XXX@2011"; $smtp_host="smtp.163.com"; $from="XXX@163.com"; $headers = "Content-Type: text/html; charset=\"gb2312\"\r\nContent-Transfer-Encoding: base64"; $lb="\r\n"; $hdr = explode($lb,$headers); $body= $body; if($body) { $bdy = preg_replace("/^\./","..",explode($lb,$body)); } $smtp = array( array("EHLO ".$loc_host.$lb,"220,250","HELO error: "), array("AUTH LOGIN".$lb,"334","AUTH error:"), array(base64_encode($smtp_acc).$lb,"334","AUTHENTIFICATION error : "), array(base64_encode($smtp_pass).$lb,"235","AUTHENTIFICATION error : ") ); $smtp[] = array("MAIL FROM: <".$from.">".$lb,"250","MAIL FROM error: "); $smtp[] = array("RCPT TO: <".$to.">".$lb,"250","RCPT TO error: "); $smtp[] = array("DATA".$lb,"354","DATA error: "); $smtp[] = array("From: ".$from.$lb,"",""); $smtp[] = array("To: ".$to.$lb,"",""); $smtp[] = array("Subject: ".$subject.$lb,"",""); foreach($hdr as $h) { $smtp[] = array($h.$lb,"",""); } $smtp[] = array($lb,"",""); if($bdy) { foreach($bdy as $b) { $smtp[] = array(base64_encode($b.$lb).$lb,"",""); } } $smtp[] = array(".".$lb,"250","DATA(end)error: "); $smtp[] = array("QUIT".$lb,"221","QUIT error: "); $fp = @fsockopen($smtp_host, 25); if (!$fp) echo "Error: Cannot conect to ".$smtp_host." "; while($result = @fgets($fp, 1024)) { if(substr($result,3,1) == " ") { break; } } $result_str=""; foreach($smtp as $req) { @fputs($fp, $req[0]); if($req[1]) { while($result = @fgets($fp, 1024)) { if(substr($result,3,1) == " ") { break; } }; if (!strstr($req[1],substr($result,0,3))) { $result_str.=$req[2].$result." "; } } } @fclose($fp); return $result_str; } |
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12476590/viewspace-701674/ ,如需转载,请注明出处,否则将追究法律责任。