2016-12-06 5 views
4

phpmailerを使用して電子メールを送信しています.HTMLコードの内容をフォームckeditorに挿入する際に問題がありますが、データは電子メールテキストのみに送信されます。phpmailerを使用してckeditorからhtmlとしてメールを送信する方法

この私のコードです:私は間違って

+0

を、あなたは有効にする必要があります* PHPMailerオブジェクトの.isHTML(真)メソッドを使用したHTML *コンテンツの配信 – RomanPerekhrest

答えて

4

を行ったかわからない

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>"; 
}} 

あなたは$body = $_POST['editor'];

にこの行 $body = strip_tags($_POST['editor']); を編集して、メールの前に次の行を追加必要 $mail->isHTML(true); を送信

機能strip_tagsはHTMLマークアップを削除します。

しかし、別の方法でフィルタ値が必要です。

+0

この作品に感謝の男性 –

1

strip_tags()関数は、あなたの投稿の値からすべてのタグを削除します

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

この行を編集してください。あなたは、htmlタグを取得することはできません。

だから、コードを編集してください。このライン

$mail->isHTML(true); 

を追加して、PHPのメーラーでHTMLを有効にして、この方法を試してみてください。

これは私の場合は問題ありません。

+0

ありがとう、すべてが完了しました –

+0

今、あなたはメールを受け取りますか? –

+0

メールがきれいに届きました –

0

あなたはCodeIgniterのを使用している場合はやっている場合、あなたは問題に直面する可能性があります

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

をあなたがやってそれを修正することができます:@Artem Ilchenkoが述べたように

$body = $_POST['some_field_with_html_body']; 
関連する問題