当前位置: 代码迷 >> PHP >> 用socket发邮件 有个有关问题
  详细解决方案

用socket发邮件 有个有关问题

热度:52   发布时间:2016-04-28 22:16:38.0
用socket发邮件 有个问题
我看网上的用socket发邮件 
基本上都是吧内容让在
Subject :

XXXXXXX 就是这个地方了
.

但是我加了标签之后如div 
总是会被转义

那在内容中放张图片进去  直接接收不到了......郁闷
改怎么办了???
代码如下


class aMail{
public static $smtp_prot = 25;
public static $debug = true;
public static $crlf  = "\r\n";
var $smtp_host;
var $login_name;
var $password;
var $form;
var $to;
var $err;
var $message;
var $socket;
function __construct($options=""){
if($options == "" || !is_array($options)){
return false;
}
foreach($options as $key=>$val){
$this->$key = $val;
}
}

function sendMail(){  
$this->socket = fsockopen($this->smtp_host,self::$smtp_prot);
$socket = $this->socket;
$crlf   = self::$crlf;
stream_set_blocking($socket,true);
$this->message = fgets($socket,512);
echo $this->message;
if(!$this->print_messsage("/^220/","connect fail")){
return false;
}

fputs($socket,"EHLO 127.0.0.1 ".$crlf);
$this->message = fgets($socket, 512);
if(!$this->print_messsage("/^2/","EHLO fail")){
return false;
}

fputs($socket,"AUTH LOGIN".$crlf);
$this->message = fgets($socket, 512);
$this->print_messsage("/^2/","AUTH LOGIN fail");

fputs($socket,base64_encode($this->login_name).$crlf);
$this->message = fgets($socket, 512);
$this->print_messsage("/^2/","login_name fail");

fputs($socket,base64_encode($this->password).$crlf);
$this->message = fgets($socket, 512);
$this->print_messsage("/^2/","password fail");

fputs($socket,"MAIL FROM: <".$this->from.">".$crlf);
$this->message = fgets($socket, 512);
$this->print_messsage("/^2/","from fail");

fputs($socket,"RCPT TO: <".$this->to.">".$crlf);
$this->message = fgets($socket, 512);
$this->print_messsage("/^334|^2/","to fail");

fputs($socket,"DATA".$crlf);
$this->message = fgets($socket, 512);
$this->print_messsage("/^334|^2/","DATA fail");

$html = implode("",array(
"To: ".$this->to.$crlf,
"From: ".$this->from.$crlf,
"Subject: ".$this->subject.$crlf.$crlf,
$this->content.$crlf.".".$crlf,
));

fputs($socket,$html);
$this->message = fgets($socket, 512);
$this->print_messsage("/^2/","html fail");

fputs($socket, "QUIT".$crlf);
$this->message=fgets($socket,512);
$this->print_messsage("/^2/","QUIT fail");
}
function print_messsage($reg="",$err=""){
$message = $this->message;
if(preg_match($reg,$message)<=0){
$this->err = $err."___".$message."--------------";
echo $err."___".$message."--------------<br>";
return false;
}
if(self::$debug){
echo $this->message."<br>";
}
return true;
}
}
$mail_options = array(
"smtp_host"=>"smtp.sina.com.cn",
"login_name"=>"ycwtt0527",
  相关解决方案