티스토리 뷰

반응형

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

한글이 깨져 보인다.

 

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

$this->email->set_crlf( "\r\n" );

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

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

 

 

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

$content = file_read($_SERVER['DOCUMENT_ROOT']."/html/mail_form.html");
$content = str_replace('::user_name::', $user_info['user_name'], $content);
		

$to = 'mail1@mail.com, mail2@mail.com';
$title = '[BRTECH] Hello email';
		
		
$config['mailtype']  = "html";
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.office365.com';
$config['smtp_user'] = 'myaccounts@mail.com';
$config['smtp_pass'] = 'password';
$config['smtp_port'] = '587';
$config['smtp_crypto'] = 'tls';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";

$config['dsn'] = true;
$this->load->library('email', $config);
		
$this->email->set_header('Content-Type', 'text/html');
$this->email->from('myaccounts@mail.com', 'from name');
$this->email->to($to);
$this->email->subject($title);
$this->email->set_mailtype("html");
$this->email->set_crlf( "\r\n" );
$this->email->message($content);
		
$sent = $this->email->send();
		
		
if ($sent)
{
	echo 'OK';
} else {
	echo $this->email->print_debugger();
}

 

php codeigniter email encoding problem

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

반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함