就是封装了个类!用这个对象去发!能发成功!但是就是太慢!老是超时
<?php
//Building class
class MailSender {
var $sender;
var $recipient;
var $oggetto;
var $body;
  var $mailformat;  // 1 &#938;txt, 0&#938;html
var $priority;
  var $recipient_CC;
  var $recipient_BCC;
  var $attachedfile; //Check sender
 function Sender($sender) {
  if ($sender=="") {
  $sender = "[email protected]";
  // $this->ErrorOutput(2);
  } else {
  if (!eregi("^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,4}$", $sender)) {
   $this->ErrorOutput(4);  
   } else $this->mittente=$sender;
  }
 } //Check recipient
 function Recipient($recipient) {
  if ($recipient=="") {
   $this->ErrorOutput(1);
  } else {
  if (!eregi("^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,4}$", $recipient)) {
   $this->ErrorOutput(3);
   } else $this->destinatario=$recipient;
  }
 } //Check subject
 function Subject($oggetto) {
  if ($oggetto!="") {
  $oggetto=str_replace("\'","'",$oggetto);
  $this->oggetto=$oggetto;  
  }
 } //Check body
 function Body($body) {
  if ($body!="") {
   $body=str_replace("\'","'",$body);
   $this->body=$body;
  }
 } //Check mailformat
 function Mailformat($mailformat) {
  if ($mailformat!="") {
   if ($mailformat!="1" && $mailformat!="0") {
     $this->ErrorOutput(5); 
   } else $this->formato=$mailformat;
  }
 } //Check priority
 function Priority($priority) {
  if ($priority!="") {
   if ($priority!="5" && $priority!="3" && $priority!="1") {
     $this->ErrorOutput(6); 
   } else $this->priorita=$priority;
  }
 } //Check recipient CC
 function RecipientCC($recipientCC) {
  if ($recipientCC!="") {
   if (!eregi("^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,4}$", $recipientCC)) {
     $this->ErrorOutput(7);
   } else $this->destinatarioCC=$recipientCC;
  }
 } //Check recipient BCC
 function RecipientBCC($recipientBCC) {
  if ($recipientBCC!="") {
   if (!eregi("^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,4}$", $recipientBCC)) {
     $this->ErrorOutput(8);
   } else $this->destinatarioBCC=$recipientBCC;
  }
 } //Check attachment
 function Attachment($attachedfile) {
  if ($attachedfile) {
  $pf=@fopen($attachedfile,"r") or die($this->ErrorOutput(9));
  $bytes=fread($pf,filesize($attachedfile));
  $file=chunk_split(base64_encode($bytes));
  fclose($pf);
  }
  if (!$file) {
   $this->ErrorOutput(9);
  } else {
   $this->allegato=$attachedfile;
   $this->filestream=$file;
   }
  } //Main function of sendmail
 function Execute()
 {
  //Setting up headers
  $forma=($this->formato==1)? "plain" : "html";
  $headers= "From: $this->mittente\n";
  $headers.= "cc: $this->destinatarioCC\n";
  $headers.= "Bcc: $this->destinatarioBCC\n";
  $headers.= "X-Priority: $this->priorita\n";
  $headers.= "X-Mailer: 'soit! Mailer'\n";
  $headers.= "Content-Type: text/$forma; charset=gb2312"; 
  $this->headers=$headers;
 if ($this->allegato) {
  $headers.= "MIME-version: 1.0\n";
  $headers.= "Content-type: multipart/mixed; "; 
  $headers.= "boundary=\"Message-Boundary\"\n";
  $headers.= "Content-transfer-encoding: 7BIT\n";
  $this->headers=$headers;
 }
 //ReSet the body's headers if we have the attachment
 if ($this->allegato) {
  $body = "--Message-Boundary\n";
  $body .= "Content-Type: text/$forma; charset=iso-8859-1\n"; 
  $body .= "Content-transfer-encoding: 7bit\n";
  $body .= "Content-description: Mail message body\n";
  $body .= $this->body."\n";
  $body .= "--Message-Boundary\n";
  $body .= "Content-type: application/octet-stream name=\"".basename($this->allegato)."\"\n"; 
  $body .= "Content-Transfer-Encoding: base64\n";
  $body .= "Content-disposition: attachment; filename=\"".basename($this->allegato)."\"\n";
  $body .= $this->filestream."\n";
  $body .= "--Message-Boundary--\n";
  $this->body=$body;
 } //Sending mail
 mail($this->destinatario, $this->oggetto, $this->body, $this->headers);
 //echo "Mail delivered to <strong>$this->destinatario</strong>";
 }function SendMail($Title, $Cont, $Recvr)
{
$this->Sender();
$this->Recipient($Recvr);
$this->Subject($Title);
$this->Body($Cont);
$this->Mailformat("0");
$this->Priority("3");
$this->Execute();
} function ErrorOutput($err_code) {
  if ($err_code!="") {
   switch($err_code) {
    case 1  : $err_msg="ERROR: Enter the recipient address!";
  break;
    case 2  : $err_msg="ERROR: Enter the sender address!";
  break;
    case 3  : $err_msg="ERROR: Mail address of sender is not valid!";
  break;
    case 4  : $err_msg="ERROR: Mail address of recipient is not valid!";
  break;
    case 5  : $err_msg="ERROR: The mailformat must be 0(html) or 1(textplain)";
  break;
    case 6  : $err_msg="ERROR: Set the priority 5(low), 3(normal), 1(high)";
  break;
    case 7  : $err_msg="ERROR: Mail address of CC recipient is not valid!";
  break;
    case 8  : $err_msg="ERROR: Mail address of BCC recipient is not valid!";
  break;
    case 9  : $err_msg="ERROR: File doesn't exists!";
  break;
    default : $err_msg="ERROR: Generic error!";
  break;
   }
  //echo $err_msg;
 // exit;
  }
 }
}
?>

解决方案 »

  1.   

    建议用phpmailer。呵呵。
    现成的封装好的开源的类,为什么不用呢。
      

  2.   

    你的php.ini里的mail部分是怎么配的
      

  3.   

    是linux服务器![mail function]
    ; For Win32 only.
    SMTP = localhost
    smtp_port = 25; For Win32 only.
    ;sendmail_from = [email protected]; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
    ;sendmail_path =
      

  4.   

    哦,你的是通过本地运行着的sendmail发信。
    建议用phpmailer类。

    ;sendmail_path =
    的注释去掉。
    sendmail_path = /usr/sbin/sendmail;你的sendmail的实际路径。http://gudai.cnblogs.com/archive/2006/03/10/346867.html