본문 바로가기
노마드 노트

PHP 메일 발송용으로 만들어본것!

by 이영훈 태천인(이영훈) 2021. 9. 20.
728x90
<?php
header("Content-type:text/html;charset=utf-8");

function getSendMail($to,$from,$subject,$content,$html) {
	if ($html == 'TEXT') $content = nl2br(htmlspecialchars($content));
	$to_exp   = explode('|', $to);

	print_r($to_exp);
	$from_exp = explode('|', $from);
	$To = $to_exp[1] ? "\"".getUTFtoKR($to_exp[1])."\" <$to_exp[0]>" : $to_exp[0];
	$Frm = $from_exp[1] ? "\"".getUTFtoKR($from_exp[1])."\" <$from_exp[0]>" : $from_exp[0];
	$Header = "From:$Frm\nReply-To:$frm\nX-Mailer:PHP/".phpversion();
	$Header.= "\nContent-Type:text/html;charset=EUC-KR\r\n"; 
	return @mail($To,getUTFtoKR($subject),getUTFtoKR($content),$Header);
}

function getUTFtoKR($str) { return iconv('utf-8','euc-kr',$str); }

$to = "to@aa.com";
$from = "from@bbb.com";
$subject = "제목";
$content = "내용";
$html = "TEXT";

getSendMail($to,$from,$subject,$content,$html);

?>
728x90

댓글0