使用 CKeditor 工具后,在电子邮件上获得 HTML 个标签
After using CKeditor tools getting HTML Tags on emails
我正在尝试发送一封有效的电子邮件,但我收到的消息带有 HTML 标签,就像我在编辑器的帮助下写的 "Hello everyone! How are you guys"
我用粗体文本发送邮件一样.
但是我收到了 <strong>Hello</strong><strong> everyone! How are you guys</strong>
这样的邮件。
我试过 CKEDITOR.config.autoParagraph = false;
它会起作用,除非你没有使用 CKE 工具栏,但如果我们使用编辑器更改文本然后在邮件上获得 HTML 标签。
是否有任何选项可以只显示邮件中的文本?
检查下方 link 使用 CKEditor 工具后,我在电子邮件中收到类似的输出
http://prntscr.com/g0tzaa
PHP 代码我在这里获取字符串并发送到邮件
HTMl
<textarea name="mailbody" id="editor1" class="form-control"></textarea>
编辑器脚本
CKEDITOR.replace( 'editor1' );
CKEDITOR.config.autoParagraph = false;
PHP代码
$mailbody=$_POST['mailbody'];
PHP 邮寄代码
function send($email,$subject, $mailbody){
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'mail.domain.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "ab@domain.com";
//Password to use for SMTP authentication
$mail->Password = "Pass#@123";
$mail->setFrom('ab@domain.com', '');
//Set the subject line
$mail->addAddress=$email;//just for example
$mail->Subject = $subject;
$mail->Body =$mailbody;
}
您的邮件以文本形式接收消息您需要以 html 形式发送消息
在 sendmail
方法
中设置内容类型
"Content-Type: text/html; charset=UTF-8"
我不知道你用什么语言发送邮件,如果我有更多详细信息,我可以提供正确的编码谢谢
编辑:
失踪:
`$mail->isHTML(true);`
我常用的邮寄方式:
public function send_mail($to, $subject, $body, $from = NULL, $from_name = NULL, $attachment = NULL, $cc = NULL, $bcc = NULL) {
try {
$mail = new PHPMailer;
$mail->isSMTP();
// $mail->SMTPDebug = 1;
$mail->Host = $this->Settings->smtp_host;
$mail->SMTPAuth = true;
$mail->Username = $this->Settings->smtp_user;
$mail->Password = $this->Settings->smtp_pass;
$mail->SMTPSecure = !empty($this->Settings->smtp_crypto) ? $this->Settings->smtp_crypto : false;
$mail->Port = $this->Settings->smtp_port;
if ($from && $from_name) {
$mail->setFrom($from, $from_name);
$mail->setaddReplyToFrom($from, $from_name);
} elseif ($from) {
$mail->setFrom($from, $this->Settings->site_name);
$mail->addReplyTo($from, $this->Settings->site_name);
} else {
$mail->setFrom($this->Settings->default_email, $this->Settings->site_name);
$mail->addReplyTo($this->Settings->default_email, $this->Settings->site_name);
}
$mail->addAddress($to);
if ($cc) { $mail->addCC($cc); }
if ($bcc) { $mail->addBCC($bcc); }
$mail->Subject = $subject;
$mail->isHTML(true); //need to set this true for html emails
$mail->Body = $body;
if ($attachment) {
if (is_array($attachment)) {
foreach ($attachment as $attach) {
$mail->addAttachment($attach);
}
} else {
$mail->addAttachment($attachment);
}
}
if (!$mail->send()) {
throw new Exception($mail->ErrorInfo);
return FALSE;
}
return TRUE;
} catch (phpmailerException $e) {
throw new Exception($e->errorMessage());
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
}
这完全取决于您使用的邮件程序。我使用 PEAR Mail_Mime 并且基本上 $body_html
来自 CKeditor
的输出
$mime = new Mail_mime("\n");
$body_txt = strip_tags($body_html);
$mime->setHTMLBody($body_html);
$mime->setTXTBody($body_txt . "\n\n");
加上一些额外的代码来设置 From/To/Subject headers 等
典型的电子邮件将包含纯文本部分和 HTML 部分。纯文本在某些情况下用于预览,在一些较旧的 text-only 客户端中。如果可用,绝大多数现代电子邮件客户端都会显示 HTML。 strip_tags
只是删除纯文本版本的所有 HTML 标签。
如果您使用的电子邮件程序非常简单,那么它不会有 mime 格式,并且根据 Internet 电子邮件的默认定义,它会将文本视为纯文本。如果是这种情况,那么只需使用 strip_tags 来清理它,尽管您可能想添加一个 str_replace
以首先将一些标签更改为 \n 或 \r\n 以便有行电子邮件文本中断。
我正在尝试发送一封有效的电子邮件,但我收到的消息带有 HTML 标签,就像我在编辑器的帮助下写的 "Hello everyone! How are you guys"
我用粗体文本发送邮件一样.
但是我收到了 <strong>Hello</strong><strong> everyone! How are you guys</strong>
这样的邮件。
我试过 CKEDITOR.config.autoParagraph = false;
它会起作用,除非你没有使用 CKE 工具栏,但如果我们使用编辑器更改文本然后在邮件上获得 HTML 标签。
是否有任何选项可以只显示邮件中的文本?
检查下方 link 使用 CKEditor 工具后,我在电子邮件中收到类似的输出 http://prntscr.com/g0tzaa PHP 代码我在这里获取字符串并发送到邮件
HTMl
<textarea name="mailbody" id="editor1" class="form-control"></textarea>
编辑器脚本
CKEDITOR.replace( 'editor1' );
CKEDITOR.config.autoParagraph = false;
PHP代码
$mailbody=$_POST['mailbody'];
PHP 邮寄代码
function send($email,$subject, $mailbody){
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'mail.domain.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "ab@domain.com";
//Password to use for SMTP authentication
$mail->Password = "Pass#@123";
$mail->setFrom('ab@domain.com', '');
//Set the subject line
$mail->addAddress=$email;//just for example
$mail->Subject = $subject;
$mail->Body =$mailbody;
}
您的邮件以文本形式接收消息您需要以 html 形式发送消息
在 sendmail
方法
"Content-Type: text/html; charset=UTF-8"
我不知道你用什么语言发送邮件,如果我有更多详细信息,我可以提供正确的编码谢谢
编辑:
失踪:
`$mail->isHTML(true);`
我常用的邮寄方式:
public function send_mail($to, $subject, $body, $from = NULL, $from_name = NULL, $attachment = NULL, $cc = NULL, $bcc = NULL) {
try {
$mail = new PHPMailer;
$mail->isSMTP();
// $mail->SMTPDebug = 1;
$mail->Host = $this->Settings->smtp_host;
$mail->SMTPAuth = true;
$mail->Username = $this->Settings->smtp_user;
$mail->Password = $this->Settings->smtp_pass;
$mail->SMTPSecure = !empty($this->Settings->smtp_crypto) ? $this->Settings->smtp_crypto : false;
$mail->Port = $this->Settings->smtp_port;
if ($from && $from_name) {
$mail->setFrom($from, $from_name);
$mail->setaddReplyToFrom($from, $from_name);
} elseif ($from) {
$mail->setFrom($from, $this->Settings->site_name);
$mail->addReplyTo($from, $this->Settings->site_name);
} else {
$mail->setFrom($this->Settings->default_email, $this->Settings->site_name);
$mail->addReplyTo($this->Settings->default_email, $this->Settings->site_name);
}
$mail->addAddress($to);
if ($cc) { $mail->addCC($cc); }
if ($bcc) { $mail->addBCC($bcc); }
$mail->Subject = $subject;
$mail->isHTML(true); //need to set this true for html emails
$mail->Body = $body;
if ($attachment) {
if (is_array($attachment)) {
foreach ($attachment as $attach) {
$mail->addAttachment($attach);
}
} else {
$mail->addAttachment($attachment);
}
}
if (!$mail->send()) {
throw new Exception($mail->ErrorInfo);
return FALSE;
}
return TRUE;
} catch (phpmailerException $e) {
throw new Exception($e->errorMessage());
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
}
这完全取决于您使用的邮件程序。我使用 PEAR Mail_Mime 并且基本上 $body_html
来自 CKeditor
$mime = new Mail_mime("\n");
$body_txt = strip_tags($body_html);
$mime->setHTMLBody($body_html);
$mime->setTXTBody($body_txt . "\n\n");
加上一些额外的代码来设置 From/To/Subject headers 等
典型的电子邮件将包含纯文本部分和 HTML 部分。纯文本在某些情况下用于预览,在一些较旧的 text-only 客户端中。如果可用,绝大多数现代电子邮件客户端都会显示 HTML。 strip_tags
只是删除纯文本版本的所有 HTML 标签。
如果您使用的电子邮件程序非常简单,那么它不会有 mime 格式,并且根据 Internet 电子邮件的默认定义,它会将文本视为纯文本。如果是这种情况,那么只需使用 strip_tags 来清理它,尽管您可能想添加一个 str_replace
以首先将一些标签更改为 \n 或 \r\n 以便有行电子邮件文本中断。