首先要有phpmailer的类,到官方网站去下,官方网站地址:http://www.phpdoc.org/
下面我是在php5下phpmailer的的邮件测试,可以发送邮件
把以下代码保存到lanshuimail.php文件或你自己的文件名称
<?php
//引入phpmailer类
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$address = 'lanshuibingdao@126.com'; //$_POST['address']; //发件人地址
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "mail.xihucms.com"; // specify main and backup server (邮局)
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "abc@xihucms.com"; // SMTP username (用户名)
$mail->Password = "******"; // SMTP password (密码)
$mail->From = "lanshuibingdao@gmail.com"; // 发件人邮箱(如果人家回复的话就是回这个邮箱)
$mail->FromName = "8比特管理员"; // 发件人
$mail->CharSet = "gb2312"; //指定字符集
$mail->Encoding = "base64"; //邮件的编码方式
$mail->AddAddress("$address", ""); //添加收件人邮箱和姓名
//$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 设置邮件格式是HTML
$mail->Subject = "PHPMailer test"; // 邮件主题
// 邮件内容
$mail->Body = '<html><head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=GB2312"></head>
<body>
欢迎来到<a href="http://www.8bits.com">8比特</a> <br /><br />
感谢您注册为本站会员!<br /><br />
</body>
</html> ';
$mail->AltBody ="text/html"; //设置是在邮件正文不支持HTML的备用显示
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
else
echo '<script language="javascript">alert("Message has been sent");</script>';
?>