php
  • email
  • diacritics
  • 2012-05-14 2 views 3 likes 
    3

    악센트가있는 제목이 포함 된 전자 메일을 보내는 데 문제가 있습니다. 나는 모든 곳에서 수색했으며 모든 해결책이 효과가 없습니다.액센트가있는 PHP 메일

    $headers = "MIME-Version: 1.0" . $endl; 
    $headers .= 'Content-type: text/html; charset="iso-8859-1"' . $endl; 
    $headers .= 'Content-Transfer-Encoding: 8bit'; 
    

    :

    나는 캐릭터, 주제, 아마 명령 줄 스크립트

    $res = shell_exec(sprintf("php mail.php %s %s %s %s", 
        escapeshellarg($email->sender), 
        escapeshellarg($receiver->email), 
        escapeshellarg($email->subject), 
        escapeshellarg($email->message) 
    )); 
    

    그리고 메일의 헤더를 통해 전송, ISO-8859-1으로 인코딩이 결과로, 나는 ???? 주제에

    참고 : Windows에서 테스트, 로컬 호스트

    샘플 코드

    testmail.php

    <?php 
    $sender = "[email protected]"; 
    $receiver = "[email protected]"; 
    $subject = "Accentued éàèçô letters"; 
    $msg = "Accentued éàèçô letters"; 
    
    shell_exec(sprintf('LANG="fr_FR.iso88591"; php mail.php %s %s %s %s > /dev/null 2>/dev/null &', 
             escapeshellarg($sender), 
             escapeshellarg($receiver), 
             escapeshellarg($subject), 
             escapeshellarg($msg) 
            )); 
    ?> 
    

    mail.php

    <?php 
    
    if ($argc!=5) exit; 
    
    $sender = $argv[1]; 
    $receiver = $argv[2]; 
    $subject = $argv[3]; 
    $msg = $argv[4]; 
    
    $endl = "\r\n"; 
    
    //HTML header 
    $headers = "From: $sender" . $endl; 
    $headers .= "MIME-Version: 1.0" . $endl; 
    $headers .= "Content-type: text/html; charset=iso-8859-1" . $endl; 
    $headers .= 'Content-Transfer-Encoding: 8bit'; 
    
    
    $msg = " 
         <html> 
         <head> 
         <title></title> 
         </head> 
         <body> 
           $msg 
         </body> 
        </html> 
        "; 
    
    $receiver = explode(',', $receiver); 
    
    foreach ($receiver as $rec) 
    { 
        mail($rec, $subject, $msg, $headers); 
        sleep(5); 
    } 
    ?> 
    

    실행 : php testmail.php Linux에서 테스트되었습니다.

    해결 이 문제에 대한 올바른 해결책은 base64_encode

    '=?UTF-8?B?' . base64_encode($subject) . '?='; 
    
    +1

    http://stackoverflow.com/questions/1719149/send-emails-with-international-accent-and-special-characters 허용되는 답변 하단을 참조하십시오. – pbond

    +1

    ** 아마도 인코딩 되었습니까? ** 적절한 구두점과 악센트는 사용되는 인코딩에 의존합니다 !! _probably_ 좋지 않습니다! 사용중인 인코딩이 무엇인지 확실히 알아야합니다. – Zuul

    +0

    @ peterbond : 시도했다. 먼저 사용해야하는 콘텐츠 유형 text/plain이 아닙니다.둘째, 시도 base64 인코딩하지만 행운을 빕니다. 문제는 명령 줄 인코딩에 있으며 Windows에서는 Windows-1252입니다. 다른 시스템에서는 다를 수 있습니다. –

    답변

    1

    좋아, 귀하의 질문에 업데이트 된 코드 많은 테스트 후, 여기에 현재 코드를 기반으로 작업 솔루션이 사용하는 것입니다

    에게

    MAIL.PHP(UTF8 인코딩 저장된 파일)

    0,123,866,428,

    TESTMAIL.PHP(UTF8 인코딩으로 저장된 파일)

    <?php 
    
    $sender = "[email protected]"; 
    $receiver = "[email protected]"; 
    $subject = "Accentued éàèçô letters"; 
    $msg = "Accentued éàèçô letters"; 
    
    setlocale(LC_CTYPE, "en_US.UTF-8"); 
    shell_exec(sprintf('"LANG=en_US.UTF-8"; php mail.php %s %s %s %s > /dev/null 2>/dev/null &', 
             escapeshellarg($sender), 
             escapeshellarg($receiver), 
             escapeshellarg($subject), 
             escapeshellarg($msg) 
            )); 
    ?> 
    

    나는 이것을 테스트하고 정확하게 모든 메일을 받았습니다.

    +0

    나는 그것을 시험해 보았지만 여전히 운이 없다.이 상황을 에뮬레이트하기위한 스크립트를 작성할 수 있습니까? 실제로 LANG = "fr_FR.iso88591"을 사용했습니다. 시도했지만 utf8, \ ",없이; 등 ... 여전히 작동하지 않습니다. 프랑스어 키보드를 사용하여 악센트 부호가있는 문자를 입력하십시오. –

    +0

    여기에서 테스트 할 수 있도록 전체 PHP 코드로 답변을 업데이트하십시오! – Zuul

    +0

    작동하지 않습니다. 리눅스에서 비어있는 대신에 –

    0

    전자 메일 헤더가 7 비트 US-ASCII가 아닌 경우 RFC2047으로 인코딩되어야합니다. 이미 가지고있는 MIME 선언은 헤더가 아니라 본문을 포함합니다.

    일반적으로 전자 메일 작동 방법을 배우지 않는 한 편안하고 정확한 해결책은이 자료를 올바르게 처리하는 라이브러리를 찾는 것입니다. 필자는 PHP에 익숙하지 않지만 StackOverflow에 대한 일반적인 질문이며 종종 대답은 PEAR와 관련이있는 것으로 보입니다.

    +0

    참조 http://stackoverflow.com/questions/7983965/cannot-display-french-accents-in-php-mail – tripleee

    관련 문제