PHPMAIL实例

<?php
//引入phpmailer类
require("phpmailer/class.phpmailer.php");

$mail = new PHPMailer();
$address = '9948425@qq.com'; //$_POST['address']; //发件人地址
$mail->IsSMTP();              // set mailer to use SMTP
$mail->Host = "smtp.163.com";     // specify main and backup server (邮局)
$mail->SMTPAuth = true;          // turn on SMTP authentication
$mail->Username = "hal_1983@163.com";   // SMTP username          (用户名)
$mail->Password = "xxxxx";        // SMTP password          (密码)
$mail->From = "hal_1983@163.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>';
?>


 

posted @ 2011-07-11 19:01  情义俩难全  阅读(186)  评论(0)    收藏  举报