本人对PHP一窍不通,但客户要求我用PHP写一个用户反馈信息的功能,但到最后一步时出错,我不太清楚出错的原因,希望各位高手指点迷津~这个功能是用户在网页上留下自己的姓名、邮件地址、意见,然后通过邮件的形式把这些内容发给管理员。
我是使用phpmailer来实现发邮件的,以下是我的代码---------------------------这是用户填写个人信息的页面,只填姓名、邮件地址、个人意见即可。SendEmail.php<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head><body>
<form name="phpmailer" action="send.php" method="post">
  <table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr> 
      <td width="25%" height="26"><div align="right">Name:</div></td>
      <td width="75%"><input type="text" name="txtName"></td>
    </tr>
    <tr> 
      <td height="26"><div align="right">E-mail Address:</div></td>
      <td><input type="text" name="txtAddress"></td>
    </tr>
    <tr> 
      <td height="26" valign="top">
<div align="right">Content:</div></td>
      <td><textarea name="txtContent"></textarea></td>
    </tr>
    <tr> 
      <td height="26"><div align="right"></div></td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td height="26">&nbsp;</td>
      <td><input type="submit" name="Submit" value="Yes">
        <input type="reset" name="Submit2" value="Reset"> </td>
    </tr>
  </table>
</form></body>
</html>
----------------------------这是发邮件的代码页send.php<html>
<head>
<title>Untitled</title>
</head><body><?php
require("class.phpmailer.php");$mail = new PHPMailer();
$sName = $_POST['txtName'];
$sAddress = $_POST['txtAddress'];
$sContent = $_POST['txtContent'];$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "smtp.yeah.net"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "[email protected]"; // SMTP username
$mail->Password = "xxxxxx"; // SMTP password$mail->From = "$sAddress";
$mail->FromName = "$sName";
$mail->AddAddress("[email protected]","");
//$mail->AddAddress(""); // name is optional
//$mail->AddReplyTo("", "");//$mail->WordWrap = 50; // set word wrap to 50 characters
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // add attachments
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // optional name
//$mail->IsHTML(true); // set email format to HTML$mail->Subject = "客户意见";
$mail->Body = "$sContent";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";if(!$mail->Send())
{
 echo "Message could not be sent. <p>";
 echo "Mailer Error: " . $mail->ErrorInfo;
 exit;
}echo "Message has been sent";
?></body>
</html>--------------------------------------每次我发送邮件后,总会提示出错:Message could not be sent. 
Mailer Error: SMTP Error: From address [[email protected]] failed

解决方案 »

  1.   

    其中[email protected]是管理员的邮件地址,那个[email protected]是用户的邮件地址。出错的原因是什么呢?是要设置SMTP服务器吗?我的系统是XP,已经安装SMTP组件
      

  2.   

    报错说你的smtp有问题。你手动测试一下telnet xxx 25
    > mail from : [email protected]  
    > ...
    看看能否通过,另外可以查看smtp日志。
      

  3.   

    from 应该是你的邮件[email protected]才对.怎么变成了[email protected]?
    另外yeah.net支持smtp吗?
      

  4.   

    wildlily980(小李) ( ) 信誉:100 from 应该是你的邮件[email protected]才对.怎么变成了[email protected]?
    另外yeah.net支持smtp吗?
    _____________________________________________-因为这个是用户发邮件给管理员的功能,所以管理员邮件地址是固定的,我使用[email protected].而FROM(用户地址)可以是任何地址。其实这代码原本就是实现管理员发封给用户,但我要的是一个反向的过程,就是用户发信给管理员,所以现在就成了这个样子。按照原本的代码,yeah.net是支持SMTP,我已试过~
      

  5.   

    Aylazhang(春暖花开) ( ) 信誉:100 报错说你的smtp有问题。你手动测试一下telnet xxx 25
    > mail from : [email protected]  
    > ...
    看看能否通过,另外可以查看smtp日志。-----------------------------------------TELNET完毕:220 XXX Microsoft ESMTP MAIL Service, Version:6.0.2600.2180 ready at Mon,27 Aug 2007 12:25:57 +0000
    email from : [email protected]
    500 5.3.3 Unrecognized command
      

  6.   

    email from : [email protected] #这里应该是 mail from: xxx   ,其中的xxx就是你发信所用的邮箱,这个可以是真实的(如果你想收到退信等信息的话),也可以是任意其他的。
      

  7.   

    在telnet一次mail from : [email protected]
    503 5.5.2 Send hello first
      

  8.   

    如果是SMTP服务器的问题,那么我应该怎样设置?代码部分又应该怎样写?我按照网上的教程,设置了SMTP服务器,并将部分代码改成这样:$mail->IsSMTP(); // set mailer to use SMTP
    $mail->Host = "服务器名称"; // specify main and backup server
    $mail->SMTPAuth = true; // turn on SMTP authentication
    $mail->Username = ""; // SMTP username
    $mail->Password = ""; // SMTP password---------------------结果出错,提示:
    Mailer Error: SMTP Error: Could not authenticate那么,究竟我应该怎样设置SMTP,这部分代码如何写呢?