初次下载安装调试 http://phpmailer.codeworxtech.com
安装:
打开电脑里的PHP.INI文件,找到如下位置,添加红线部分的内容,路径就是PHPMailer存放的位置
![](http://hiphotos.baidu.com/rokaye/pic/item/ef86f6f49a0446c9f3d38511.jpg)
保存,重启apache.
实例:
test.php
<html>
<body>
<h3>phpmailer Unit Test</h3>
请你输入<font color="#FF6666">收信</font>的邮箱地址:
<form name="phpmailer" action="send.php" method="post">
<input type="hidden" name="submitted" value="1"/>
邮箱地址: <input type="text" size="50" name="address" />
<br/>
<input type="submit" value="发送"/>
</form>
</body>
</html>
send.php
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->CharSet = "gb2312"; // 这里指定字符集!如果是utf-8则将gb2312修改为utf-8
$mail->Encoding = "base64";
$address = $_POST['address'];
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "smtp.126.com"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = ""; // SMTP username
$mail->Password = "******"; // SMTP password
$mail->From = "";
$mail->FromName = "rokaye";
$mail->AddAddress("$address", "");
//$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 = "PHPMailer测试邮件";
$mail->Body = "Hello,这是rokaye的测试邮件";
$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";
?>
phpmailer发送邮件时产生乱码解决
这里因为发送邮件是您没有指定您所要求的编码。
$mail->CharSet = "gb2312"; // 这里指定字符集!如果是utf-8则将gb2312修改为utf-8
$mail->Encoding = "base64";
OK,加上以上代码就好了!