PHPMailer是一个用于发送电子邮件的PHP函数包。它提供的功能包括:
*.在发送邮时指定多个收件人,抄送地址,暗送地址和回复地址
*.支持多种邮件编码包括:8bit,base64,binary和quoted-printable
*.支持SMTP验证
*.支持冗余SMTP服务器
*.支持带附件的邮件和Html格式的邮件
*.自定义邮件头
*.支持在邮件中嵌入图片
*.调试灵活
*.经测试兼容的SMTP服务器包括:Sendmail,qmail,Postfix,Imail,Exchange等
*.可运行在任何平台之上

require("class.phpmailer.php");    $mail = new PHPMailer();    $mail->IsSMTP();					// 启用SMTP  $mail->Host = "smtp1.example.com";			//SMTP服务器  $mail->SMTPAuth = true;					//开启SMTP认证  $mail->Username = "name@example.com";			// SMTP用户名  $mail->Password = "password";				// SMTP密码    $mail->From = "from@example.com";			//发件人地址  $mail->FromName = "Mailer";				//发件人  $mail->AddAddress("josh@example.net", "Josh Adams");	//添加收件人  $mail->AddAddress("ellen@example.com");  $mail->AddReplyTo("info@example.com", "Information");	//回复地址  $mail->WordWrap = 50;					//设置每行字符长度  /** 附件设置  $mail->AddAttachment("/var/tmp/file.tar.gz");		// 添加附件  $mail->AddAttachment("/tmp/image.jpg", "new.jpg");	// 添加附件,并指定名称  */  $mail->IsHTML(true);					// 是否HTML格式邮件    $mail->Subject = "Here is the subject";			//邮件主题  $mail->Body    = "This is the HTML message body <b>in bold!</b>";		//邮件内容  $mail->AltBody = "This is the body in plain text for non-HTML mail clients";	//邮件正文不支持HTML的备用显示    if(!$mail->Send())  {     echo "Message could not be sent. <p>";     echo "Mailer Error: " . $mail->ErrorInfo;     exit;  }    echo "Message has been sent";

关于邮件乱码的解决办法:

邮件的中文会出现乱码主要是编码没有设置好。

设置方法如下:

$mail->IsHTML(true);					// 是否HTML格式邮件  $mail->CharSet = "utf-8";				// 这里指定字符集!  $mail->Encoding = "base64";   

但是请注意,这并不能完全保证你收到的邮件是正确的编码。在发送html邮件时,我们需要发送一个完整的html文档。

如:

<html><head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>含中文的内容</body>
</html>