谢谢各位,总算搞定了。原来安装了postfix后就不用phpmailer了。 直接用mail()函数就可以发送邮件了,超级简单。smtp的服务器 密码什么都不需要了。
<?php
$to ="[email protected]";
$subject="test";
$msg="smtp test";
$headers="From:[email protected]";if(mail("$to","$subject","$msg","$headers"))
echo"success";
else
echo"fail";
?>

解决方案 »

  1.   

    没密码?很可能到时被认为是SPAM的
      

  2.   

    得配置自己的邮件服务器或者还使用smtp用户认证方式,
    要不然就会被认为是垃圾邮件,
    严重的会被封IP,直接拒收~
      

  3.   

    我是折腾了很久的phpmailer 用smtp认证的,但是死活发不出去。在windows下面弄得是好好的,发邮件都正常的,但是一到ubuntu就不灵了
      

  4.   

     我用下面这个代码测试,在windwons下面好的,为什么在linux下面就不可以了呢。奇怪,都已经最精简了<?php  
    require_once("./lib/class.phpmailer.php");
    include("lib/class.smtp.php");
    $mail=new PHPMailer();
    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
    $mail->SMTPAuth   = true;                  // SMTP authentication
    $mail->Host       = 'smtpcom.263xmail.com'; // SMTP server
    $mail->From ='[email protected]';
    $mail->FromName='Web';
    $mail->Subject='My subject';
    $mail->Body ='Hello World';
    $mail->AddAddress('[email protected]','xx');$mail->Username   = "[email protected]"; // SMTP 账户名
    $mail->Password   = "x";        // SMTP 账户密码
     
    if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
    exit;
    } else {
    echo "Message sent!";
       }
       
    ?>
     
      

  5.   

    下面用来phpmailer 又用了 $mail->IsSendmail() ,这个算smtp认证了还是没有认证啊require '../class.phpmailer.php';  
      
    try {  
        $mail = new PHPMailer(true); //New instance, with exceptions enabled  
      
        $body             = file_get_contents('contents.html');  
        $body             = preg_replace('/\\\\/','', $body); //Strip backslashes  
      
        $mail->IsSMTP();                           // tell the class to use SMTP  
        $mail->SMTPAuth   = true;                  // enable SMTP authentication  
        $mail->Port       = 25;                // set the SMTP server port  
        $mail->Host       = "smtp.xxxx.com"; // SMTP server  
        $mail->Username   = "[email protected]";     // SMTP server username  
        $mail->Password   = "xxxx";            // SMTP server password  
      
        $mail->IsSendmail();  // tell the class to use Sendmail  
      
        $mail->AddReplyTo("[email protected]","xxxx");  
      
        $mail->From       = "[email protected]";  
        $mail->FromName   = "DJB";  
      
        $to = "[email protected]";  
      
        $mail->AddAddress($to);  
      
        $mail->Subject  = "First PHPMailer Message";  
      
        $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test  
        $mail->WordWrap   = 80; // set word wrap  
      
        $mail->MsgHTML($body);  
      
        $mail->IsHTML(true); // send as HTML  
      
        $mail->Send();  
        echo 'Message has been sent.';  
    } catch (phpmailerException $e) {  
        echo $e->errorMessage();  
    }  
    ?>  
         
      

  6.   

    没有人好心点告诉我这ubuntu下好用的发邮件代码吗
      

  7.   

    ubuntu下安装sendmail就行了
    apt-get install sendmail