<?php
/*
 * Created on 2010-9-9
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */  require("/phpmailer/class.phpmailer.php");   $mail = new PHPMailer();
  $address = $_POST['address'];
  $mail->IsSMTP();
  $mail->Host = "192.168.0.132";
  $mail->SMTPAuth = true;
  $mail->Username = "[email protected]";
  $mail->Password = "elwg324";
  $mail->From = "[email protected]";
  $mail->FromName = "您的名称";
  $mail->AddAddress("$address", "");
  $mail->Subject = "PHPMailer测试邮件";
  $mail->Body = "Hello,这是测试邮件";
  $mail->AltBody = "This is the body in plain text for non-HTML mail clients";
  if(!$mail->Send())
  {
  echo "邮件发送失败. <p>";
  echo "错误原因: " . $mail->ErrorInfo;
  exit;
  }
  echo "邮件发送成功";
?>我运行程序时,一直报错
Parse error: syntax error, unexpected T_VARIABLE in D:\www\mail\send.php on line 11 就是$mail = new PHPMailer();这行,怎么回事啊,请求帮助啊。

解决方案 »

  1.   

    你代码每一行前面有一个不可见的控制字符,所以有问题,修改如下:
    <?php
    /*
     * Created on 2010-9-9
     *
     * To change the template for this generated file go to
     * Window - Preferences - PHPeclipse - PHP - Code Templates
     */
    require("/phpmailer/class.phpmailer.php");
    $mail = new PHPMailer();
    $address = $_POST['address'];
    $mail->IsSMTP();
    $mail->Host = "192.168.0.132";
    $mail->SMTPAuth = true;
    $mail->Username = "[email protected]";
    $mail->Password = "elwg324";
    $mail->From = "[email protected]";
    $mail->FromName = "您的名称";
    $mail->AddAddress("$address", "");
    $mail->Subject = "PHPMailer测试邮件";
    $mail->Body = "Hello,这是测试邮件";
    $mail->AltBody = "This is the body in plain text for non-HTML mail clients";
    if(!$mail->Send()){
    echo "邮件发送失败. <p>";
    echo "错误原因: ".$mail->ErrorInfo;
    exit;
    }
    echo "邮件发送成功";
    ?>