本人对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> </td>
</tr>
<tr>
<td height="26"> </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
我是使用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> </td>
</tr>
<tr>
<td height="26"> </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
> mail from : [email protected]
> ...
看看能否通过,另外可以查看smtp日志。
另外yeah.net支持smtp吗?
另外yeah.net支持smtp吗?
_____________________________________________-因为这个是用户发邮件给管理员的功能,所以管理员邮件地址是固定的,我使用[email protected].而FROM(用户地址)可以是任何地址。其实这代码原本就是实现管理员发封给用户,但我要的是一个反向的过程,就是用户发信给管理员,所以现在就成了这个样子。按照原本的代码,yeah.net是支持SMTP,我已试过~
> 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
503 5.5.2 Send hello first
$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,这部分代码如何写呢?