2016-12-06 40 views
4

我使用phpmailer發送電子郵件,當在表單ckeditor中插入html代碼的內容時,我遇到問題,但數據僅發送到電子郵件文本。如何使用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>"; 
}} 

我不知道錯在哪裏

+0

作爲@Artem Ilchenko提到,您需要啓用* HTML *內容通過' .isHTML(true)'方法傳遞 – RomanPerekhrest

回答

4

你需要編輯此行 $body = strip_tags($_POST['editor']);$body = $_POST['editor'];

而且加入這行郵寄 $mail->isHTML(true);

功能strip_tags刪除html標記。

但是您需要另一種方式的過濾器值。

+0

這個工作感謝人 –

1

請編輯此行

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

用strip_tags()函數將從您的帳值去除所有標籤。你不能得到的HTML標籤。

請加入這一行

$mail->isHTML(true); 

使你的PHP郵件的HTML所以,請編輯代碼,並嘗試這種方式。

這對我來說工作正常。

+0

感謝所有人完成 –

+0

現在你收到郵件了嗎? –

+0

傳入郵件如此完美謝謝 –

0

如果您正在使用笨,你可能,如果這樣做面臨一個問題:

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

您可以通過執行修復:

$body = $_POST['some_field_with_html_body']; 
相關問題