[英]How to use phpmailer and send mail as html from ckeditor
I'm use phpmailer to sending email, I have problems when inserting the contents of the html code on the form ckeditor, but data sent to the e-mail text only. 我使用phpmailer发送电子邮件,我在ckeditor表单上插入html代码的内容时遇到问题,但数据仅发送到电子邮件文本。
This is my code: 这是我的代码:
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>";
}}
I do not know what went wrong 我不知道出了什么问题
You need edit this row $body = strip_tags($_POST['editor']);
你需要编辑这行
$body = strip_tags($_POST['editor']);
to $body = $_POST['editor'];
to
$body = $_POST['editor'];
And add this line before mail send $mail->isHTML(true);
并在邮件发送
$mail->isHTML(true);
之前添加此行$mail->isHTML(true);
Function strip_tags removes html markup. 函数strip_tags删除html标记。
But you need filter value another way. 但是你需要另一种方式来过滤价值。
Please edit this line 请编辑此行
$body = strip_tags($_POST['editor']); to $body = $_POST['editor'];
the strip_tags() function will remove all tags from your posted value. strip_tags()函数将从发布的值中删除所有标记。 The you cant get the the html tags.
你不能得到HTML标签。
Please enable html in your PHP mailer by adding this line 请通过添加此行在PHP邮件程序中启用html
$mail->isHTML(true);
So please edit the code and try this way. 所以请编辑代码并尝试这种方式。
This is working fine in my case. 这在我的情况下工作正常。
If you are using Codeigniter, you might face a problem if doing: 如果您使用的是Codeigniter,则在执行以下操作时可能会遇到问题:
$body = $this->input->post('some_field_with_html_body');
You can fix it by doing: 你可以通过这样做来解决它:
$body = $_POST['some_field_with_html_body'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.