这是我在网上找的一个发邮件的类   但是当邮件发送成功后 却无内容请问大家如何解决
<?php 
set_time_limit(120); 
class smtp_mail 

var $host; //主机 
var $port; //端口 一般为25 
var $user; //smtp认证的帐号 
var $pass; //认证密码 
var $debug = false; //是否显示和服务器会话信息? 
var $conn; 
var $result_str; //结果 
var $in; //客户机发送的命令 
var $from; //源信箱 
var $to; //目标信箱 
var $subject; //主题 
var $body; //内容 
var $socket;
function smtp_mail($host,$port,$user,$pass,$debug=false) 

$this->host = $host; 
$this->port = $port; 
$this->user = base64_encode($user); 
$this->pass = base64_encode($pass); 
$this->debug = $debug; 
$this->socket = socket_create (AF_INET, SOCK_STREAM, SOL_TCP); //具体用法请参考手册 
if($this->socket) 

$this->result_str = "创建socket:".socket_strerror(socket_last_error()); 
$this->debug_show($this->result_str); 

else 

exit("初始化失败,请检查您的网络连接和参数"); 

$this->conn = socket_connect($this->socket,$this->host,$this->port); 
if($this->conn) 

$this->result_str = "创建socket连接:".socket_strerror(socket_last_error()); 
$this->debug_show($this->result_str); 

else 

exit("初始化失败,请检查您的网络连接和参数"); 

$this->result_str = "服务器应答:<font color=#cc0000>".socket_read ($this->socket, 1024)."</font>"; 
$this->debug_show($this->result_str); 

function debug_show($str) 

if($this->debug) 

echo $str."<p>\r\n"; 


function send($from,$to,$subject,$body) 

if($from == "" || $to == "") 

exit("请输入信箱地址"); 

if($subject == "") $sebject = "无标题"; 
if($body == "") $body = "无内容"; 
$this->from = $from; 
$this->to = $to; 
$this->subject = $subject; 
$this->body = $body; 
$all = "from:".$this->from."\n"; 
$all .= "to:".$this->to."\n"; 
$all .= "subject:".$this->subject."\n"; 
$all .= $this->body; 
/* 
如过把$all的内容再加处理,就可以实现发送mime邮件了 
不过还需要加很多程序 
*/ 
//以下是和服务器会话 
$this->in = "ehlo helo\r\n"; 
$this->docommand(); 
$this->in = "auth login\r\n"; 
$this->docommand(); 
$this->in = $this->user."\r\n"; 
$this->docommand(); 
$this->in = $this->pass."\r\n"; 
$this->docommand(); 
$this->in = "mail from:".$this->from."\r\n"; 
$this->docommand(); 
$this->in = "rcpt to:".$this->to."\r\n"; 
$this->docommand(); 
$this->in = "data\r\n"; 
$this->docommand(); 
$this->in = $all."\r\n.\r\n"; 
$this->docommand(); 
$this->in = "quit\r\n"; 
$this->docommand(); 
//结束,关闭连接 

function docommand() 

socket_write ($this->socket, $this->in, strlen ($this->in)); 
$this->debug_show("客户机命令:".$this->in); 
$this->result_str = "服务器应答:<font color=#cc0000>".socket_read ($this->socket, 1024)."</font>"; 
$this->debug_show($this->result_str); 


?>//这个是我做的测试,我用的是smtp.163.com,那你的信箱也必须是163.com的,要不人家不让你发!! 
   //你用这个类的时候你修改成你自己的信箱就可以了 
   $smtp = new smtp_mail("smtp.163.com","25","xxx163.com","xx",true); 
   //如果你需要显示会话信息,请将上面的修改成 
   //$smtp = new smtp_mail("smtp.163.com","25","你的163.com的帐号","你的密码",true); 
   $smtp->send("<xx>","<xx>","你好","你好 快放假了哦"); 

解决方案 »

  1.   

    请使用Phpmailer。百发百中无敌手。调用:
    //发送邮件
    date_default_timezone_set('PRC');
    include_once('phpMailer/class.phpmailer.php');
    $mail = new PHPMailer();
    $mail->CharSet = "utf-8"; //设置采用gb2312编码,也可以是gbk,注意要和本页文件编码一致
    $body='内容内容可以为html<br><p><img><div>';
    $mail->IsSMTP(); 
    $mail->Host       = "smtp.163.com"; // SMTP server,163的smtp服务器,不过新注册的163不支持了
    $mail->SMTPAuth = true; // turn on SMTP authentication 
    $mail->Username = "newhope68"; // SMTP username。email登陆用户名
    $mail->Password = "xinxiwang"; // SMTP password。email密码
    $mail->From       = "[email protected]";
    $mail->FromName   = "艾米唯尔";
    $mail->Subject    = "柬埔寨旅游在线订单备忘邮件";
    $mail->WordWrap = 50; //50字换行,不过不知道中文如何
    $mail->MsgHTML($body);
    $mail->AddAddress($email, $name);//收件人
    if(!$mail->Send()) {
      echo "Mailer Error: " . $mail->ErrorInfo;
    }
      

  2.   

    在我的电脑上你的类直接不能用,这种状况也是最近才出现的,我写的mail类也是使用163的smtp,最近一直无法正常发信,所以我就用gmail来发信,挺好用的你下载一个phpmailer,然后用以下的代码,借助gmail来发信吧
    <?php//error_reporting(E_ALL);
    error_reporting(E_STRICT);date_default_timezone_set('America/Toronto');require_once('../class.phpmailer.php');
    //include("class.smtp.php"); //可选,会自动从class.phpmailer.php加载$mail=new PHPMailer();$body=file_get_contents('contents.html');
    $body=Strtr($body,Array("\\"=>""));//$body= eregi_replace("[\]",'',$body);$mail->IsSMTP(); // 告诉程式要使用SMTP
    $mail->SMTPDebug  = 2; // 开启 SMTP debug 信息 (测试时使用)// 1 = 错误和消息// 2 = 只有消息
    $mail->SMTPAuth   = true; // 开启 SMTP 验证
    $mail->SMTPSecure = "ssl"; // sets the prefix to the servier
    $mail->Host       = "smtp.gmail.com"; // sets GMAIL as the SMTP server
    $mail->Port       = 465; // set the SMTP port for the GMAIL server
    $mail->Username   = "[email protected]"; // GMAIL用户名
    $mail->Password   = "???"; // GMAIL密码$mail->SetFrom('[email protected]',''); //发信人邮件地址及用户名(用户名中文会乱码)
    //$mail->AddReplyTo("[email protected]",""); //回复地址及用户名$subject='這是郵件標題';
    $mail->Subject    = "=?UTF-8?B?".base64_encode($subject)."?= ";$mail->MsgHTML($body);$mail->AddAddress("[email protected]",""); //接收者邮件地址及用户名(用户名中文会乱码)//附件
    //$mail->AddAttachment("images/phpmailer.gif");      // attachment
    //$mail->AddAttachment("images/phpmailer_mini.gif"); // attachmentif(!$mail->Send()) {
    echo "Mailer Error: ".$mail->ErrorInfo;
    }else{
    echo "Message sent!";
    }?>