PHPmailer发送邮件及邮件出现乱码的处理

初次下载安装调试 http://phpmailer.codeworxtech.com
安装:
打开电脑里的PHP.INI文件,找到如下位置,添加红线部分的内容,路径就是PHPMailer存放的位置

保存,重启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,加上以上代码就好了!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值