php 使用phpmailer 发送邮件(附带中文乱码的解决方法)
下载phpmailer ,在程序里包含class.phpmailer.php 类 ,这里有中文乱码的解决方法
实例代码如下
<html>
<head>
<title>PHPMailer - Mail() basic test</title>
</head>
<body> <?php
//header( "Content-type: text/html; charset=UTF-8" ); //设置本地编码
//setlocale( LC_ALL, 'GBK' );
//error_reporting(E_ALL);
error_reporting( E_STRICT ); date_default_timezone_set( 'America/Toronto' ); require_once('class.phpmailer.php'); //必须包含的文件
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded $mail = new PHPMailer();
$mail->CharSet = "UTF-8"; //中文环境下需要设置编码
// $body = file_get_contents( 'contents.html' ); //包含网页的使用方法
//$body = eregi_replace( "[\]", '', $body );
$body = '测试邮件,附上中文乱码解决方法:' . "<br>" .'123'; //设置邮件内容 使用 <br> 换行
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.163.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "smtp.163.com"; // 邮箱服务器地址
$mail->Port = 25; // 邮箱服务器端口
$mail->Username = "1xxxxxxx@163.com"; // 你的邮箱用户名
$mail->Password = "abcdefg@0"; // 你的邮箱密码 $mail->SetFrom( '1xxxxxxx@163.com', '小----洋 ' ); //发送人 //$mail->AddReplyTo( "2xxxxxxxx@qq.com", "亲" ); //接收方 $mail->Subject = "=?utf-8?B?" . base64_encode( "我是标题" ) . "?="; //解决中文标题乱码问题 设置标题 $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->MsgHTML( $body );
$address = "sheapchen@163.com";
$mail->AddAddress( $address, "John Doe" ); //$mail->AddAttachment( "附件1" ); // attachment //这里可以添加附件
// $mail->AddAttachment( "附件2" ); // attachment if ( !$mail->Send() ) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?> </body>
</html>
php 使用phpmailer 发送邮件(附带中文乱码的解决方法)的更多相关文章
- xShell终端中文乱码完全解决方法
xShell终端中文乱码完全解决方法 xShell(xShell5)以及其他终端中文乱码的原因无非有三种:(1)Linux系统的编码问题:(2)xShell终端的编码问题: (3)两端的语言编码不一致 ...
- Mysql命令行中文乱码的解决方法
环境:Windows 8 64位,Mysql 5.0.96 for Win64 (x86) 数据库本身安装时默认已经是使用utf8编码的了,但在命令行中执行查询时,查询到的中文依然乱码,解决方法如下 ...
- 30. CentOS终端命令行显示中文乱码的解决方法
安装CentOS的时候选择了中文,结果在终端不能显示中文,都是乱码,解决方法:修改/etc/sysconfig/i18n,内容为 代码如下: LANG="zh_CN.GB18030&qu ...
- windows下SVN日志反馈中文乱码的解决方法
转自:https://shiyousan.com/post/635889908703806636 TortoiseSVN中文乱码的问题困扰了我好久,特别是每次使用“以标准差异文件显示修改”时,打开的文 ...
- 【IntelliJ IDEA】从资源文件读取出来就中文乱码的解决方法
在application.properties资源文件中设置两个自定义的属性以及属性值: com.sxd.name = "德玛西亚" com.sxd.want = "王者 ...
- ueditor 1.4.3 gbk asp 上传中文乱码 终极解决方法 ie6 ie8 也适用
[摘要:百度编纂器1.43 gbk asp 题目 1.firefox3.0下 单图上传 面没有了 面多图上传 中央的蓝色按钮(即 面击挑选图片)没有表现(附件上传出那个题目) 没有晓得我的水狐吃翔了 ...
- Sublime Text 3 中文乱码的解决方法
Sublime Text 3 中文乱码表现如下图: 解决方法很简单,三步搞定: 步骤一: 下载ConvertToUTF8,下载地址:http://pan.baidu.com/s/1gd5SWmB 步骤 ...
- mysql命令行以及mysql workbence查询结果中文乱码的解决方法
最近正在学习mysql,安装环境是windows server 2003 32位操作系统+mysql 5.1.47同时也安装了mysql命令行以及mysql workbench这里是test数据库cr ...
- android studio中文乱码的解决方法【转】
一. 在android的源文件中的乱码问题 Android Studio安装后发现所有的中文,不管是界面上的还是输出的log中的中文都变成小框框,具体的解决方法如下, 可以肯定是字体的问题 解决:菜单 ...
随机推荐
- 控制台应用程序的Main方法
总结一下Main方法规则: 1.Main 方法名大小写有规范. 2.Main 方法返回类型只有 void.int两种返回类型. 3.Main 方法的参数可以是string[] args,也可以为空,只 ...
- MapReduce实例
1.WordCount(统计单词) 经典的运用MapReuce编程模型的实例 1.1 Description 给定一系列的单词/数据,输出每个单词/数据的数量 1.2 Sample a is b is ...
- Visual Studio 自定义控件不显示在工具箱
工具=>选项=>Windows窗体设计器=>常规=>AutoToolBoxPopulate=>True
- 李洪强iOS开发之后使用纯代码实现横向滚动的UIScrollView
李洪强iOS开发之后使用纯代码实现横向滚动的UIScrollView (VTmagic是一个实现左右滚动的控制器的框架,也可以实现此功能) 实现的效果: 01 - 创建四个控制器 02 - 定义需要 ...
- shape和selector的结合使用
shape和selector是Android UI设计中经常用到的,比如我们要自定义一个圆角Button,点击Button有些效果的变化,就要用到shape和selector.可以这样说,shape和 ...
- linux shell 命令学习(2) paste - merge lines of files
paste - merge lines of files 命令格式: paste [OPTION] ... [FILE] ... 说明: 输出每个文件的对应行组合而成的行,中间用tab分开,如果没有F ...
- jsp中的out对象 和 servlet中的response.getOutputStream()
web容器生成的servlet代码中有out.write(””),这个和JSP中调用的response.getOutputStream()产生冲突. 即Servlet规范说明,不能既调用 respon ...
- CentOS Mysql自动备份 .txt
http://fly.b3log.org/articles/2011/10/25/1319505473928.html MySql数据库备份: 说明:我这里要把MySql数据库存放目录/var/lib ...
- SpringBoot配置属性之Server
SpringBoot配置属性系列 SpringBoot配置属性之MVC SpringBoot配置属性之Server SpringBoot配置属性之DataSource SpringBoot配置属性之N ...
- MySQL —— 程序连接时的驱动名称和URL
CONNECTION_DRIVER : com.mysql.jdbc.Driver CONNECTION_URL : jdbc:mysql://localhost/DB_NAME