php PHPmailer 发送 HTML 代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11140263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 23:49:47  来源:igfitidea点击:

PHPmailer sending HTML CODE

php

提问by user580950

I am using PHPmailer to send email.

我正在使用 PHPmailer 发送电子邮件。

I have also used HTML = True content type

我还使用了 HTML = True 内容类型

    $mail = new PHPMailer();

$mail->IsSMTP();                    // send via SMTP
$mail->Host     = $Host; 
$mail->SMTPAuth = true;             // turn on SMTP authentication
$mail->Username = $Username;  
$mail->Password = $Password; 

$mail->From     = $From;
$mail->FromName = $FromName;

    $mail->AddAddress($To , $ToName);

$mail->WordWrap = 50;               // set word wrap
    $mail->Priority = 1; 
$mail->IsHTML(true);  
$mail->Subject  =  $Subject;
$mail->Body     =  $Body;

Once the email is sent i see the actual HTML code instead of the contents please check below

发送电子邮件后,我会看到实际的 HTML 代码而不是内容,请检查以下内容

enter image description here

在此处输入图片说明

**Not sure what is the issue **

**不知道是什么问题**

回答by Nabil Kadimi

Calling the isHTML()method after the instance Bodyproperty (I mean $mail->Body) has been set solved the problem for me:

isHTML()在设置实例Body属性(我的意思是$mail->Body)之后调用该方法为我解决了这个问题:

$mail->Subject = $Subject;
$mail->Body    = $Body;
$mail->IsHTML(true);       // <=== call IsHTML() after $mail->Body has been set.

回答by Atombit

// Excuse my beginner's english

// 原谅我的初学者英语

There is msgHTML() method, which, also, call IsHTML().

有 msgHTML() 方法,它也调用 IsHTML()。

Hrm... name IsHTMLis confusing...

嗯……名字有点IsHTML乱……

/**
 * Create a message from an HTML string.
 * Automatically makes modifications for inline images and backgrounds
 * and creates a plain-text version by converting the HTML.
 * Overwrites any existing values in $this->Body and $this->AltBody
 * @access public
 * @param string $message HTML message string
 * @param string $basedir baseline directory for path
 * @param bool $advanced Whether to use the advanced HTML to text converter
 * @return string $message
 */
public function msgHTML($message, $basedir = '', $advanced = false)

回答by adq82

or if you have still problems you can use this

或者如果你仍然有问题,你可以使用它

$mail->Body =  html_entity_decode($Body);

回答by Mladen Janjetovic

In version 5.2.7 I use this to send plain text: $mail->set('Body', $Body);

在 5.2.7 版本中,我使用它来发送纯文本: $mail->set('Body', $Body);

回答by Ibrahim Khan

just you need to pass true as an argument to IsHTML() function.

只是您需要将 true 作为参数传递给 IsHTML() 函数。

回答by shailendra pathak

do like this-paste your html code inside your separate html file using GET method.

这样做 - 使用 GET 方法将您的 html 代码粘贴到您单独的 html 文件中。

$mail->IsHTML(true);                                 
    $mail->WordWrap = 70;                                 
    $mail->addAttachment= $_GET['addattachment']; $mail->AltBody   
    =$_GET['AltBody'];  $mail->Subject = $_GET['subject']; $mail->Body = $_GET['body'];

回答by odide

all you need to do is just add $mail->IsHTML(true); to the code it works fine..

您需要做的只是添加 $mail->IsHTML(true); 到代码它工作正常..