教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 PHPmailer发送邮件及乱码问题的解决

PHPmailer发送邮件及乱码问题的解决

发布时间:2016-01-15   编辑:jiaochengji.com
为大家介绍一个PHPMailer发送邮件的简单例子,并就出现的乱码问题给出一个解决方法,有需要的朋友,可以参考下。

PHPMailer的下载地址:http://phpmailer.codeworxtech.com
安装:
打开PHP.INI文件,找到如下位置,添加红线部分的内容,路径就是PHPMailer存放的位置:
a href=http://www.jbxue.com/wb/php/ target=_blank class=infotextkeyphp/amailer配置
保存,重启apache。

举一个phpmailer发信的例子。

1、邮件发送页
 

复制代码 代码示例:
<html>
<body>
<h3>phpmailer邮件发送测试-www.jbxue.com</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>

2、发邮件程序 send.php
 

复制代码 代码示例:

<?php
/**
* PHPMailer邮件发送
* Edit www.jbxue.com
*/
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";
?>

有关乱码的问题,多是因为没有指定所要求的编码而引起的。
 

复制代码 代码示例:
$mail->CharSet = "gb2312"; // 指定字符集!如果是utf-8则将gb2312修改为utf-8
$mail->Encoding = "base64";
 

这样操作后,就不会出现乱码了。
 

您可能感兴趣的文章:
PHPMailer发送邮件的实例分享
phpmailer发送gmail邮件的例子
phpmailer发送网易126邮箱的例子
phpmailer发送yahoo邮件的例子
phpmailer类实现邮件群发的实例代码
PHPMailer发送邮件代码实例(ubuntu系统)
PHPMailer发送带附件邮件的例子
PHPMailer收发邮件标题、发件人、内容乱码问题的终极解决方法
PHPMailer发送邮件中文附件名乱码的解决办法
PHPMailer邮件标题中文乱码的解决方法
PHPMailer邮件类发送邮件举例(163邮箱)
phpmailer 发送邮件中文乱码问题的解决方法总结
phpmailer发送邮件及实现密码找回功能的代码
PHPmailer邮件群发的入门例子
PHPmailer 邮件群发的范例参考
phpmailer发邮件中文乱码问题如何解决
phpmailer 类发送邮件乱码解决方法
PHPMailer批量发送邮件的实例代码
有关phpmailer的用法
php使用phpMailer发送邮件的例子
phpmailer实现的简单openvpn用户认证的代码
PHPMailer 中文使用说明
phpmailer发送邮件的例子

您可能感兴趣的文章:
phpmailer发送yahoo邮件的例子
phpmailer 类发送邮件乱码解决方法
PHPmailer邮件群发的入门例子
PHPMailer发送邮件代码实例(ubuntu系统)
PHPMailer邮件标题中文乱码的解决方法
PHPMailer发送邮件中文附件名乱码的解决办法
phpmailer发送网易126邮箱的例子
phpmailer发送gmail邮件的例子
phpmailer 发送邮件中文乱码问题的解决方法总结
phpmailer发邮件中文乱码问题如何解决

关键词: PHPMailer  发送邮件  乱码   
[关闭]
~ ~