php - 如何使用 phpmailer 并从 ckeditor 以 html 格式发送邮件

标签 php html email phpmailer

我正在使用 phpmailer 发送电子邮件,在表单 ckeditor 上插入 html 代码的内容时遇到问题,但数据仅发送到电子邮件文本。

这是我的代码:

require_once ('class.phpmailer.php');

$mail = new PHPMailer(true);
if (isset($_POST['btn_send'])) 
    {

    $smtp_username = strip_tags($_POST['username']);
    $smtp_password = strip_tags($_POST['password']);
    $ssl_port = strip_tags($_POST['port']);
    $my_smtp = strip_tags($_POST['host']);
    $my_ssl = strip_tags($_POST['type']);
    $realname = strip_tags($_POST['realname']);
    $subject = strip_tags($_POST['subject']);
    $body = strip_tags($_POST['editor']);
    $emaillist = strip_tags($_POST['emaillist']); 


//...now get on with sending...
try 
{
//$mail->isSendmail();
        $mail->isSMTP();
        $mail->Body = ($body);
        $mail->isHTML(true);
        $mail->SMTPDebug = 0;
        $mail->SMTPAuth = true;
        $mail->SMTPSecure = "$my_ssl";
        $mail->Host = "$my_smtp";
        $mail->Port = "$ssl_port";
        $mail->AddAddress($emaillist);
        $mail->Username = "$smtp_username";
        $mail->Password = "$smtp_password";
        $mail->SetFrom("$smtp_username", "$realname");
        $mail->AddAddress($emaillist);
        $mail->epriority = "3";
        $mail->AddReplyTo("$smtp_username");
        $mail->Subject = "$subject";
        $mail->encode = ("yes");
        $mail->CharSet = "utf-8";
if($mail->Send())
{
$msg = "<div class='alert alert-success'>
Hi,<br /> bro mail terkirim ke ".$emaillist."
</div>";
}
}
catch(phpmailerException $ex)
{
$msg = "<div class='alert alert-warning'>".$ex->errorMessage()."</div>";
}}

不知道哪里出了问题

最佳答案

您需要编辑此行 $body = strip_tags($_POST['editor']);$body = $_POST['editor'];

并在邮件发送之前添加这一行 $邮件->isHTML(true);

函数 strip_tags 删除 html 标记。

但是您需要另一种过滤值。

关于php - 如何使用 phpmailer 并从 ckeditor 以 html 格式发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40990445/

相关文章:

php - 安装 Asterisk 13 + FreePBX 12.0.7

javascript - 用ajax替换div内容

javascript - 在页面向下滚动时将 pageYOffset 值添加到 div 的位置

javascript - Google chrome 中的奇怪行为(提交表单后,它会转到页面底部)

html - Bash:发送带有附件的 HTML?

php - 在php中发送邮件的困难

php - 在自治系统编号 (ASN) 中获取 IP

html - SVG 的自定义路径标题

java - Java Web 应用程序的最佳邮件库

php - 无法设置 Guzzle 内容类型