How to use phpmailer and send mail as html from ckeditor

I use phpmailer to send email, I am having problems pasting the contents of the html code into the ckeditor form, but the data is sent only to the email text.

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 don’t know what went wrong.

+4
source share
3 answers

You need to edit this line $body = strip_tags($_POST['editor']); before$body = $_POST['editor'];

And add this line before sending mail $mail->isHTML(true);

The strip_tags function removes html markup.

But you need the filter value in a different way.

+4
source

Please edit this line.

$body = strip_tags($_POST['editor']); to $body = $_POST['editor'];

strip_tags() . html.

, html PHP,

$mail->isHTML(true);

, , .

.

+1

If you are using Codeigniter, you may encounter a problem if:

$body = $this->input->post('some_field_with_html_body');

You can fix this by doing:

$body = $_POST['some_field_with_html_body'];
0
source

Source: https://habr.com/ru/post/1662927/


All Articles