-1

我需要帮助。我在我的代码中使用 phpmailler.. 当我在我的 php 页面中打印正文时,它显示正确但是当我发送邮件时,我收到的邮件包含特殊字符和 html 代码,请帮助我。直到现在我找到了解决方案。

这是我的代码:

$mail = new PHPMailer();

$mail->From = $from_email;
$mail->FromName = $from_name;
$mail->Subject = $subject;
$mail->MsgHTML("Hi How are you");
$mail->CharSet = "UTF-8";
$mail->IsHTML(true);


$mail->AddBCC("surajgujar@gmail.com");
$mail->AddAddress($send_to, '');

try
{
    if($mail->Send())
    {


    }   
    else
    {

    }
}
catch(Exception $e)
{

}

我收到的邮件如下。输出:

X-Timeout-Protection: 0
X-ScanInfo: Scanning...
    Scanning...
Return-path: <sunildiwate@gmail.com>
Envelope-to: sunildiwate@gmail.com
Delivery-date: Thu, 03 Oct 2013 08:14:22 -0600
Received: from benchmb7 by box927.bluehost.com with local-bsmtp (Exim 4.80)
    (envelope-from <sunildiwate@gmail.com>)
    id 1VRjfa-0006qV-Id
    for sunildiwate@gmail.com; Thu, 03 Oct 2013 08:14:22 -0600
X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on box927.bluehost.com
X-Spam-Level: 
X-Spam-Status: No, score=-2.4 required=4.0 tests=ALL_TRUSTED,AWL,BAYES_00,
    HTML_MESSAGE,NORMAL_HTTP_TO_IP,WEIRD_PORT shortcircuit=no autolearn=ham
    version=3.3.1
Received: from [117.239.190.50] (port=51654 helo=192.168.1.245)
    by box927.bluehost.com with esmtpa (Exim 4.80)
    (envelope-from <sunildiwate@gmail.com>)
    id 1VRjfZ-0006n7-Pl
    for sunildiwate@gmail.com; Thu, 03 Oct 2013 08:14:22 -0600
Date: Thu, 3 Oct 2013 19:44:13 +0530
To: undisclosed-recipients:;
From: Body Technique <sunildiwate@gmail.com>
Subject: Jason Bourne has re-confirmed the  job assignment
Message-ID: <581ff5fd79e46bb58fbd56fb78adc1c5@192.168.1.245>
X-Priority: 3
X-Mailer: PHPMailer 5.1 (phpmailer.sourceforge.net)
MIME-Version: 1.0
Content-Type: multipart/alternative;
    boundary="b1_581ff5fd79e46bb58fbd56fb78adc1c5"
X-Identified-User:
{1048:box927.bluehost.com:benchmb7:gmail.com} {sentby:smtp auth 117.239.190.50 authed with phptest@benchmarkitsolutions.com}
X-Identified-User:
{1048:box927.bluehost.com:benchmb7:gmail.com}
{sentby:spamassassin for local delivery to identified user}
X-CTCH-PVer:  0000001
X-CTCH-Spam:  Unknown
X-CTCH-VOD:  Unknown
X-CTCH-Flags:  0
X-CTCH-RefID:
str=0001.0A09020A.524D7BE4.007E,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld
=1,fgs=0
X-CTCH-Score:  0.000
X-CTCH-ScoreCust:  0.000
X-CTCH-Rules:  
X-EMLSPAM: 0
X-EMLSPAM-SCORE: -100
X-EMLSPAM-REFID: str=0001.0A090202.524D7BE4.048E,ss=1,re=0.000,fgs=0


--b1_581ff5fd79e46bb58fbd56fb78adc1c5
Content-Type: text/plain; charset = "iso-8859-1"
Content-Transfer-Encoding: 8bit

Â
 



     
























 Jason Bournehas accepted the following job and agreed to the BT work
policies and pay scale:


Company Name: 

Date:  Thu 
Hours: 05:30 AM for  hours.
Therapist Pay for the job: 




To review this order click the link below.

Click Here ]


--b1_581ff5fd79e46bb58fbd56fb78adc1c5
Content-Type: text/html; charset = "iso-8859-1"
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
</head>
<body>
<p>&nbsp;</p>
<p>&nbsp;</p>
<table style="background-color: #ffffff; width: 100%;" dir="ltr" border="0"
cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="margin: 0;" align="left" valign="top"><br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<table class="wrapper" style="padding-bottom: 10px; border-bottom-width:
40px; border-bottom-style: solid; border-bottom-color: #ce2b39;
border-right-width: 15px; border-right-style: solid; border-right-color:
#e5e5e5; border-left-width: 15px; border-left-style: solid;
border-left-color: #e5e5e5; width: 670px;" border="0" cellspacing="0"
cellpadding="0" align="center" bgcolor="#e5e5e5">
<!--<tbody>

<p><span style="font-size: small;">Hi $contact_name,</span></p>
<p><span style="font-size: small;">Thank you for registering on the Body
Techniques - $compnametxt website.</span></p>
<p><span style="font-size: small;">As a registered user you can now schedule
appointments for onsite massage at $compnametxt.</span></p>
<p><span style="font-size: small;">Simply click on the link below to make a
reservation: $loggeduser</span></p>
<p><span style="font-size: small;">As a corporate user you can also take
advantage of these other great services from Body Techniques :</span></p>
<p><span style="font-size: small;">1. Request In-Home/Outcall service.<br
/></span></p>
<p><span style="font-size: small;">- fill in a very simple form and let our
expert staff find a great therapist who can come to you.</span></p>
<p><span style="font-size: small;">2. Shop for quality health products. <br
/></span></p>
<p><span style="font-size: small;">3. Give the gift of massage with online
Gift Certificates. <br /></span></p>
<p><span style="font-size: small;"><br /></span></p>
<p><span style="font-size: small;">Your Email: $contact_email1</span></p>
<p><span style="font-size: small;">Your Password: $pwdtxt</span></p>
<p><span style="font-size: small;"><br /></span></p>
<p><span style="font-size: small;">Thank You,</span></p>
<p><span style="font-size: small;">Body Techniques</span></p>

</tbody>-->
<tbody>
<tr>
<td style="padding: 0; margin: 0;" align="left" valign="top">
<table style="width: 100%;" border="0" cellspacing="0" cellpadding="0"
align="center">
<tbody>
<tr>
<td style="margin: 0px; padding: 0px; border-top-width: 10px;
border-top-style: solid; border-top-color: #ce2b39; padding-top: 10px;"
align="left" valign="top"><img style="border: 0px none transparent; width:
166px;"
src="</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td style="padding: 0; margin: 0;" align="left" valign="top">
<table style="width: 100%;" border="0" cellspacing="0" cellpadding="0"
align="left">
<tbody>
<tr>

</tr>
<tr>
<td style="padding: 10px 15px 25px; font-family: Arial, sans-serif; color:
#545454; background-color: #ffffff;" colspan="2" align="left" valign="top"
bgcolor="#ffffff">

<p><span style="font-size:small;"> <span style="font-family:Arial;"><span
style="color:#0f08ff;">Jason Bourne</span>has accepted the following job and
agreed to the BT work policies and pay scale:</span></span></p>
<p class="MsoNormal"><span style="font-size:small;"><span
style="font-family:Arial;"> </span></span></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"><span
style="font-family:Arial;font-size:small;">Company Name: <span
style="color:#0a03ff;"></span></span></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"><span style="font-size:small;"><span
style="font-family:Arial;">Date:  <span style="color:#0a03ff;">Thu
</span></span></span></p>
<p class="MsoNormal"><span style="font-size:small;"><span
style="font-family:Arial;">Hours: <span style="color:#0f08ff;">05:30 AM
</span>for<span style="color:#0f08ff;"> </span> hours.</span></span></p>
<p class="MsoNormal"><span style="font-size:small;"><span
style="font-family:Arial;">Therapist Pay for the job: <span
style="color:#0f08ff;"></span></span></span></p>
<p class="MsoNormal"> </p>
<p> </p>
<p class="MsoNormal"><span style="font-size:small;"><span
style="font-family:Arial;"> </span></span></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"><span style="font-family:Arial;font-size:small;">To
review this order click the link below.</span></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"><span style="font-size:small;"><span
style="font-family:Arial;"><span style="color:#0602ff;"><a
href="http://192.168.1.245//pm5/bodytechniques/working/development/version4/
therapist/sugar/" target="_blank" title="Click here">Click Here</a></span>
</span><span style="font-family:Arial;"><span
style="color:#0602ff;">]</span></span></span></p>

</td>
</tr>
</tbody>
</table>
</td>
</tr>


</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p><br /><br /><br /><br /></p>
</body>
</html>



--b1_581ff5fd79e46bb58fbd56fb78adc1c5--
4

2 回答 2

1

您的Content-Type邮件标题中的text/plain. 将其更改为text/html.

检查在 phpmailer 中添加 HTML 格式以获取更多信息

编辑:

不用担心设置邮件标题。

而不是$mail->MsgHTML使用:

$mail->Body = "<h1>html message</h1><p>message</p>";
$mail->AltBody = "plain text message";

检查PHP Mailer 教程

于 2013-10-04T06:30:51.817 回答
0

使用 UTF-8

$mail->CharSet = "UTF-8";
于 2013-10-04T06:34:17.537 回答