코드이그나이터 메일 전송시 한글 깨짐 현상 해결 방법

코드이그나이터 메일 전송시 한글 깨짐 현상 해결 방법

Jason park@ 2019. 6. 13. 15:51

코드이그나이터 메일 전송시 인코딩 설정을 했음에도 불구하고 한글이 깨질 경우, 아래와같은 현상이 발생한다.

한글이 깨져 보인다.

해결 방법은 인코딩 설정과 더불어 줄바꿈 문자를 설정해주는것이다.

$this->email->set_crlf( "\r

" );

적용후 메일을 보내 테스트 해보면 아래와같이 잘 전송되는것을 볼수 있다.

깨지는 문자 없이 잘 보인다.

아래는 html 파일을 불러서 메일을 보내는 전체 소스이다.

$content = file_read($_SERVER['DOCUMENT_ROOT']."/html/mail_form.html"); $content = str_replace('::user_name::', $user_info['user_name'], $content); $to = '[email protected], [email protected]'; $title = '[BRTECH] Hello email'; $config['mailtype'] = "html"; $config['protocol'] = 'smtp'; $config['smtp_host'] = 'smtp.office365.com'; $config['smtp_user'] = '[email protected]'; $config['smtp_pass'] = 'password'; $config['smtp_port'] = '587'; $config['smtp_crypto'] = 'tls'; $config['charset'] = 'utf-8'; $config['newline'] = "\r

"; $config['dsn'] = true; $this->load->library('email', $config); $this->email->set_header('Content-Type', 'text/html'); $this->email->from('[email protected]', 'from name'); $this->email->to($to); $this->email->subject($title); $this->email->set_mailtype("html"); $this->email->set_crlf( "\r

" ); $this->email->message($content); $sent = $this->email->send(); if ($sent) { echo 'OK'; } else { echo $this->email->print_debugger(); }

php codeigniter email encoding problem

PHP 코드이그나이터 한글 깨짐 현상 해결

from http://brtech.tistory.com/117 by ccl(A) rewrite - 2020-04-02 12:27:16