2014-10-24 2 views
0

메일을 보내는 기능을 만들었지 만 html 코드를 해석합니다. 본문에 정확한 HTML 코드를 보내려면 어떻게해야합니까? 예를 들어 사용자는 <strong>text</strong>을 받고 '굵게'는 굵게 표시되지 않아야합니다. html 코드로 phpmailer 이메일 보내기

function sendmail($dest,$subj ,$htmlmessage,$textmessage) { 
    $Mail = new PHPMailer(true); 
    try{ 

     $Mail->IsSMTP(); // Use SMTP 
     $Mail->SMTPAuth = TRUE; // enable SMTP authentication 
     //$Mail->SMTPDebug = 2; // 2 to enable SMTP debug information 

     $Mail->Host = "smtp.gmail.com"; // Sets SMTP server 
     $Mail->Username = '[email protected]'; // SMTP account username 
     $Mail->Password = 'mypassword'; // SMTP account password 
     $Mail->SMTPSecure = "ssl"; //Secure conection 
     $Mail->Port = 465; // set the SMTP port 

     $Mail->SetFrom ('[email protected]', 'def'); 
     $Mail->FromName = 'myname'; 
     //$Mail->addReplyTo('[email protected]', 'Reply here'); 

     $Mail->addAddress($dest, 'to'); // To: 
     $Mail->isHTML(false); 

     $Mail->Subject=$subj; 
     $Mail->Body=$htmlmessage; 
     $Mail->AltBody=$textmessage; 

     $Mail->Send(); 
    } 
    catch (phpmailerException $e) { 

     file_put_contents('Mailerrors.txt', $e->errorMessage() , FILE_APPEND); 
     die("Problem with emailing."); 
    } 
} 

여기에 나는 단지 그들이 HTML 코드를 해석, 메일을 함수가 작업을 수행하고 나에게 이메일을 보내는

$dest='[email protected]'; 
$subj='hello'; 
$htmlmessage='this is the body<strong>asd</strong>'; 
$textmessage='this is the body'; 

sendmail($dest,$subj, $htmlmessage,$textmessage); 

주를 보낼 수 있습니다.

+0

'$ Mail-> isHTML (true); ' – turtle

+0

여전히 코드를 HTML로 해석합니다. –

+0

'$ htmlmessage = '이 몸 ASD이다'하려고, 여전히 그것을 해석' – turtle

답변

1

여러 가지 가능한 해결책이 있습니다.

는 단지 이렇게 만 일반 텍스트를 보내려면 :

$mail->isHTML(false); 

$mail->AltBody에 아무것도 넣지 마십시오. 그렇게하면 HTML 마크 업이 포함되어 있어도 메시지가 일반 텍스트로 전송됩니다.

메시지 본문의 일부만 HTML 렌더링에서 벗어나게하려는 경우 htmlspecialchars을 사용하거나 <pre> 태그에 마크 업 부분을 포함 할 수 있습니다.

메시지 본문 전체에 htmlspecialchars을 적용하면 isHTML(false)과 비슷한 결과를 얻을 수 있지만 그다지 효율적이지는 않습니다.

0

내가 해냈어. 해야 할 일 :

$Mail->Body=htmlspecialchars($htmlmessage); 

잘 작동하는지는 모르지만 확실하지 않습니다. 나는 또 다른 방법이 있어야한다고 확신한다.