Narendra Verma Narendra Verma - 1 year ago 53
Javascript Question

After using CKeditor tools getting HTML Tags on emails

I am trying to send an email which is working but the message I am getting with HTML tags like I wrote

"Hello everyone! How are you guys"
with help of editor I did in the bold text and sent the mail.

But I got a mail like
<strong>Hello</strong><strong> everyone! How are you guys</strong>
.

I tried
CKEDITOR.config.autoParagraph = false;
it will work unless you haven't use the CKE tool bar but if we use the editor to change the text then getting HTML tags on mail.

Is there any option to display only text in the mail?

Check below link I am getting like this output in email after using CKEditor tools
http://prntscr.com/g0tzaa
PHP code I am getting string here in process and sending to mail

HTMl

<textarea name="mailbody" id="editor1" class="form-control"></textarea>


editor script

CKEDITOR.replace( 'editor1' );
CKEDITOR.config.autoParagraph = false;


PHP code

$mailbody=$_POST['mailbody'];


PHP mailing code

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 = "[email protected]";
//Password to use for SMTP authentication
$mail->Password = "Pass#@123";
$mail->setFrom('[email protected]', '');
//Set the subject line
$mail->addAddress=$email;//just for example
$mail->Subject = $subject;
$mail->Body =$mailbody;


}

Answer Source

your mail receives the message as text you need to send the message as html set content-type in your sendmail method

"Content-Type: text/html; charset=UTF-8"

i dont know what language you are using to send mail i could give proper coding if i have more details thank you

EDIT:

Missing :

 `$mail->isHTML(true);`

My general Mail Method :

    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());
        }
    }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download