PHP mail() 함수에서 utf-8 인코딩으로 메일 보내기
페이지 정보
본문
PHP mail() 함수
PHP에서 mail() 함수는 스크립트상에서 이메일을 보내는데 사용됩니다.
문법
mail(to,subject,message,headers,parameters);
<?php
$sendmailToEmail ="mail@a.com"; // 받는주소
$sendmailSubject ="mail test";
$sendmailContent ="test";
$result=mail($sendmailToEmail, $sendmailSubject, $sendmailC);
if($result) {
echo "Sendmail success";
}else {
echo "sending mail fail";
}
?>
<?php
echo "<meta charset=\"utf-8\">";
// 메일발송 시작
$sendmailFromName = "보내는이름";
$sendmailFromEmail = "보내는email";
$sendmailToName = "받는이름";
$sendmailToEmail = "받는email";
// 참조 email
$sendmailCcEmail = "";
// 숨은참조 email
$sendmailBccEmail = "";
$sendmailSubject = "메일보내기";
$sendmailContent = "
222111111내용 1<br>
내용 2<br>
";
$charset = "UTF-8";
$sendmailFromName = "=?utf-8?B?".base64_encode($sendmailFromName)."?=";
$sendmailToName = "=?utf-8?B?".base64_encode($sendmailToName)."?=";
if ($sendmailCcEmail) { $sendmailCcEmail = "=?utf-8?B?".base64_encode($sendmailCcEmail)."?="; } else { $sendmailCcEmail=""; }
if ($sendmailBccEmail) { $sendmailBccEmail = "=?utf-8?B?".base64_encode($sendmailBccEmail)."?="; } else { $sendmailBccEmail=""; }
if ($sendmailSubject) $sendmailSubject = "=?utf-8?B?".base64_encode($sendmailSubject)."?=";
//$sendmailContent = iconv('utf-8', 'euc-kr', $sendmailContent);
$sendmailHeader = "Content-Type: text/html; charset=utf-8\r\n";
$sendmailHeader .= "MIME-Version: 1.0\r\n";
//$sendmailHeader .= "Content-Transfer-Encoding: 8bit\n\n";
$sendmailHeader .= "Return-Path: {$sendmailToName} <{$sendmailFromEmail}>\r\n";
$sendmailHeader .= "From: {$sendmailFromName} <{$sendmailFromEmail}>\r\n";
$sendmailHeader .= "Reply-To: <{$sendmailFromEmail}>\r\n";
if ($sendmailCcEmail) $sendmailHeader .= "Cc: {$sendmailCcEmail}\r\n";
if ($sendmailBccEmail) $sendmailHeader .= "Bcc: {$sendmailBccEmail}\r\n";
//$sendmailBody = base64_encode(str_replace("\\", "", $sendmailContent)) . "\r\n";
$sendmailBody = $sendmailContent;
$send_mail = mail($sendmailToEmail, $sendmailSubject, $sendmailBody , $sendmailHeader);
//mail("받는email", "제목 : PHP 메일 보내기", "내용 1 \\n 내용 2 \\n 내용 3");
//echo "메일 보내기29";
$client_ip = isset($_SERVER['HTTP_CLIENT_IP'])?$_SERVER['HTTP_CLIENT_IP']:isset($_SERVER['HTTP_X_FORWARDED_FOR'])?$_SERVER['HTTP_X_FORWARDED_FOR']:$_SERVER['REMOTE_ADDR'];
//echo "client_ip = ".$client_ip."<br>"; // 아이피가 어떻게 보이는지 확인
if (count(explode(',', $client_ip))==2) {
$ip0 = explode(',',$client_ip);
$client_ip = $ip0[0];
}
if ($client_ip == "내컴퓨터IP") {
if(!$send_mail) {
echo "메일 보내기 실패";
} else {
echo "메일 발송 성공"; // 테스트 완료후 주석
}
}
// 메일발송 끝
?>
참고자료
http://anjella.tistory.com/270
http://www.waitfor.com/phpBB3/viewtopic.php?f=12&t=82
http://mdoli.com/tatter/entry/UTF-8-서버에서-메일-보내기-한글문제-해결
http://promisej7.tistory.com/579
https://ssamlee.tistory.com/16
PHP에서 mail() 함수는 스크립트상에서 이메일을 보내는데 사용됩니다.
문법
mail(to,subject,message,headers,parameters);
<?php
$sendmailToEmail ="mail@a.com"; // 받는주소
$sendmailSubject ="mail test";
$sendmailContent ="test";
$result=mail($sendmailToEmail, $sendmailSubject, $sendmailC);
if($result) {
echo "Sendmail success";
}else {
echo "sending mail fail";
}
?>
<?php
echo "<meta charset=\"utf-8\">";
// 메일발송 시작
$sendmailFromName = "보내는이름";
$sendmailFromEmail = "보내는email";
$sendmailToName = "받는이름";
$sendmailToEmail = "받는email";
// 참조 email
$sendmailCcEmail = "";
// 숨은참조 email
$sendmailBccEmail = "";
$sendmailSubject = "메일보내기";
$sendmailContent = "
222111111내용 1<br>
내용 2<br>
";
$charset = "UTF-8";
$sendmailFromName = "=?utf-8?B?".base64_encode($sendmailFromName)."?=";
$sendmailToName = "=?utf-8?B?".base64_encode($sendmailToName)."?=";
if ($sendmailCcEmail) { $sendmailCcEmail = "=?utf-8?B?".base64_encode($sendmailCcEmail)."?="; } else { $sendmailCcEmail=""; }
if ($sendmailBccEmail) { $sendmailBccEmail = "=?utf-8?B?".base64_encode($sendmailBccEmail)."?="; } else { $sendmailBccEmail=""; }
if ($sendmailSubject) $sendmailSubject = "=?utf-8?B?".base64_encode($sendmailSubject)."?=";
//$sendmailContent = iconv('utf-8', 'euc-kr', $sendmailContent);
$sendmailHeader = "Content-Type: text/html; charset=utf-8\r\n";
$sendmailHeader .= "MIME-Version: 1.0\r\n";
//$sendmailHeader .= "Content-Transfer-Encoding: 8bit\n\n";
$sendmailHeader .= "Return-Path: {$sendmailToName} <{$sendmailFromEmail}>\r\n";
$sendmailHeader .= "From: {$sendmailFromName} <{$sendmailFromEmail}>\r\n";
$sendmailHeader .= "Reply-To: <{$sendmailFromEmail}>\r\n";
if ($sendmailCcEmail) $sendmailHeader .= "Cc: {$sendmailCcEmail}\r\n";
if ($sendmailBccEmail) $sendmailHeader .= "Bcc: {$sendmailBccEmail}\r\n";
//$sendmailBody = base64_encode(str_replace("\\", "", $sendmailContent)) . "\r\n";
$sendmailBody = $sendmailContent;
$send_mail = mail($sendmailToEmail, $sendmailSubject, $sendmailBody , $sendmailHeader);
//mail("받는email", "제목 : PHP 메일 보내기", "내용 1 \\n 내용 2 \\n 내용 3");
//echo "메일 보내기29";
$client_ip = isset($_SERVER['HTTP_CLIENT_IP'])?$_SERVER['HTTP_CLIENT_IP']:isset($_SERVER['HTTP_X_FORWARDED_FOR'])?$_SERVER['HTTP_X_FORWARDED_FOR']:$_SERVER['REMOTE_ADDR'];
//echo "client_ip = ".$client_ip."<br>"; // 아이피가 어떻게 보이는지 확인
if (count(explode(',', $client_ip))==2) {
$ip0 = explode(',',$client_ip);
$client_ip = $ip0[0];
}
if ($client_ip == "내컴퓨터IP") {
if(!$send_mail) {
echo "메일 보내기 실패";
} else {
echo "메일 발송 성공"; // 테스트 완료후 주석
}
}
// 메일발송 끝
?>
참고자료
http://anjella.tistory.com/270
http://www.waitfor.com/phpBB3/viewtopic.php?f=12&t=82
http://mdoli.com/tatter/entry/UTF-8-서버에서-메일-보내기-한글문제-해결
http://promisej7.tistory.com/579
https://ssamlee.tistory.com/16
댓글목록
등록된 댓글이 없습니다.