最新消息:本站访问过程中有任何问题请与我联系……

PHP使用class.smtp.php发送邮件,并解决标题和正文乱码问题

技术教程 xx2008 4337浏览 0评论

PHP使用class.smtp.php发送邮件使用的class.smtp.php下载地址

PHP使用class.smtp.php发送邮件代码如下:

<?php
include_once("smtp.class.php");
$smtpserver = "smtp.qq.com";//SMTP服务器
$smtpserverport =25;//SMTP服务器端口
$smtpusermail = "12345qq.com";//SMTP服务器的用户邮箱
$smtpemailto = "12345@msn.cn";//发送给谁
$smtpuser = "12345";//SMTP服务器的用户帐号
$smtppass = "12345";//SMTP服务器的用户密码
$mailsubject = "=?UTF-8?B?".base64_encode("测试邮件系统")."?=";//邮件主题 


$mailbody = "<h1> 这是一个测试程序 </h1>";//邮件内容 $mailtype = "HTML";//邮件格式(HTML/TXT),TXT为文本邮件 if($_POST[submit]) { $smtp= new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass); $smtp->debug = FALSE;//是否显示发送的调试信息 $smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype); } ?> <form action="test.php" method="post"> <table> <tr> <td > <input type="submit" name="submit" value="Send"/></td> </tr> </table> </form>

使用以上代码发送邮件标题和正文应该都是正常的,网上很多代码使用起来邮件的标题和正文会乱码,解决办法如下:

一、PHP使用class.smtp.php发送邮件解决标题乱码

标题代码使用:

"=?UTF-8?B?".base64_encode("标题")."?="


二、PHP使用class.smtp.php发送邮件解决正文乱码

class.smtp.php文件中第41行:

			$header .= "Content-Type:text/html\r\n;

修改为:

			$header .= "Content-Type:text/html; charset=utf-8\r\n";

即可解决PHP使用class.smtp.php发送邮件正文乱码

转载请注明:服务器VPS折腾 » PHP使用class.smtp.php发送邮件,并解决标题和正文乱码问题

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (6)

  1. I are an inttrernet examiner and I usually glare to have specific and excellent data. I are happy you have putted such a arduous equipment ordinary sunny approach that a first-timers could appreciate it widout ny difiuclty. I genuinely appreciate your effort. Keep on the enormous work
    http://www./2016-08-09 09:01 回复
  2. Your comment made me feel better. My dad served on Guadalcanal and had great contempt for the ARC. The field director hoarded the supplies and refused GI’s a single razor blades. The valuable stores ended up rotting in the jungle mildew and were dumped into the sea.
  3. May I ask Fjordman why he thinks Australia will survive the Islamicization of the Western World and the USA will not?Almost all polls predict a Labor victory this year in Australia, and their Labor Party is as anti-American, anti-Israel, anti-Semitic, and pro-Islamist/appeasement as any European leftist party.Let's see what Fjordman has to say after 6 months of Prime Minister Rudd.Plus, does he really think Australia (population 20 million), can hold out against an Islamist Indonesia (population 220 million), if the United States (population 303 million) is defeated?
  4. If you're looking to buy these articles make it way easier.
  5. I've been looking for a post like this for an age
    erection2016-04-11 16:02 回复
  6. I'm not easily impressed. . . but that's impressing me! 🙂