programing

워드프레스 메일 헤더 세트 기타 일반 텍스트

showcode 2023. 6. 14. 21:59
반응형

워드프레스 메일 헤더 세트 기타 일반 텍스트

코드 조각에 대한 도움을 얻고 싶습니다. 메일 헤더를 text/html로 설정하는 워드프레스 테마를 사용하고 있습니다. 이로 인해 일반 텍스트 메일에 문제가 발생합니다. 줄 바꿈은 더 이상 표시되지 않습니다.

설정을 시도했습니다.

} else {
    return 'text/plain';
}

하지만 저는 php를 잘 몰라서 어디에 두어야 작동할 수 있는지 모르겠습니다.정의되지 않은 메일에 대한 텍스트/플레인을 설정하고 싶습니다.

다음은 wp 헤더의 코드입니다.

 /**
 * filter mail headers
 */
function wp_mail($compact) {
    if (isset($_GET['action']) && $_GET['action'] == 'lostpassword') return $compact;
    if ($compact['headers'] == '') {

        //$compact['headers']   = 'MIME-Version: 1.0' . "\r\n";
        $compact['headers'] = 'Content-type: text/html; charset=utf-8' . "\r\n";
        $compact['headers'].= "From: " . get_option('blogname') . " < " . get_option('admin_email') . "> \r\n";
    }

    $compact['message'] = str_ireplace('[site_url]', home_url() , $compact['message']);
    $compact['message'] = str_ireplace('[blogname]', get_bloginfo('name') , $compact['message']);
    $compact['message'] = str_ireplace('[admin_email]', get_option('admin_email') , $compact['message']);

    $compact['message'] = html_entity_decode($compact['message'], ENT_QUOTES, 'UTF-8');
    $compact['subject'] = html_entity_decode($compact['subject'], ENT_QUOTES, 'UTF-8');

    //$compact['message']       =   et_get_mail_header().$compact['message'].et_get_mail_footer();

    return $compact;
}

이를 변경하는 대신 일반 줄 바꿈을 html로 변경합니다.

$message=nl2br($message); // of course use your var name.

이렇게 하면 이메일의 표준 형식을 유지할 수 있습니다. 이 경우 일반 텍스트는 별도의 헤더가 필요할 정도로 특별한 것이 없습니다.이 함수는 모든 줄 바꿈을 html 버전으로 변환합니다.

새 줄을 제외한 대부분의 일반 텍스트는 특별한 태그가 없기 때문에 HTML 형식으로도 형식을 유지합니다.

배치 방법은 다음과 같습니다.

function wp_mail($compact) {
    // leave your existing code intact here, don't remove it.
    $compact["message"]=nl2br($compact["message"]); 
    return $compact;
}

언급URL : https://stackoverflow.com/questions/29726989/wordpress-mail-header-set-else-plain-text

반응형