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中的中文都变成小框框,具体的解决方法如下, 可以肯定是字体的问题 解决:菜单 ...
随机推荐
- HDU5569/BestCoder Round #63 (div.2) C.matrix DP
matrix Problem Description Given a matrix with n rows and m columns ( n+m is an odd number ), at fir ...
- Ajax的进阶学习(一)
在Ajax课程中,我们了解了最基本的异步处理方式.本章,我们将了解一下Ajax的一些全局请求事件.跨域处理和其他一些问题. 加载请求 在Ajax异步发送请求时,遇到网速较慢的情况,就会出现请求时间较长 ...
- Java学习笔记之:Java 流
一.介绍 Java.io包几乎包含了所有操作输入.输出需要的类.所有这些流类代表了输入源和输出目标. Java.io包中的流支持很多种格式,比如:基本类型.对象.本地化字符集等等. 一个流可以理解为一 ...
- c# 计算1-100之间的所有整数的和
求1-100所有整数和: class Program { static void Main(string[] args) { ,); Console.WriteLine("1-100之间所有 ...
- 《Linux内核设计与实现》读书笔记 - 目录 (完结)【转】
转自:http://www.cnblogs.com/wang_yb/p/3514730.html 读完这本书回过头才发现, 第一篇笔记居然是 2012年8月发的, 将近一年半的时间才看完这本书(汗!! ...
- SpringMVC上传文件以流方式判断类型附常用类型
// 此类中判断类型所截取的byte 长度暂不确定,请使用者测试过使用 package com.tg.common.other; import com.tg.common.tginterface.TG ...
- 在windows系统上安装VMware Workstation虚拟机,然后在虚拟机VMware Workstation上安装linux系统,在linux系统安装xshell的服务端,在windows系统上安装xshell。用windows系统上的xshell连接到linux
第一步:安装xshell: 去百度 xshell ,然后安装一下就可以了.就是普通的软件安装,在这里不做过多的接收. 第二步:安装虚拟机VMware Workstation 百度安装,不做过介绍 ...
- cookie使用
知识拷贝. 理论很简单,而且模式也和大多请求 http://blog.csdn.net/lanmao100/article/details/2328491(源地址).返回状态的SSO差不多.但是有几个 ...
- MTK android flash配置
关于6573集成MCP nandflash的方法,driver_allinone 和Memory Customer Document pdf的说明里面漏了很多细节.在此补上. 1.首先确认flash型 ...
- [Topcoder]ZigZag(dp)
题目链接:https://community.topcoder.com/stat?c=problem_statement&pm=1259&rd=4493 题意:给一串数字,求出最长的波 ...