묻고답하기
폼메일로 메일을 보내면 한글이 깨집니다 ㅜㅠ
2015.12.24 16:09
안녕하세요
전 html이랑 css정도만 읽을 줄 아는 초보인데, 검색해보니 php파일을 수정해야 하는것 같아서 도움을 요청합니다.
어느 분이 블로그(http://likeme.pe.kr/145)에서 제공해주신 익스텐션 프로그램(SupportFormCreator.mxp)으로 폼메일을 만들었는데요
다른건 다 괜찮은데 메일이 도착하면(한메일) 본문이외에 이름, 제목등 한글로 써져야 하는 부분이 깨져서 들어옵니다. 본문내용은 한글로 잘 나오구요,
제가 테스트한다고 했을 때 영어로만 보내봐서 뒤늦게 알게 됐거든요 영어로는 잘 나옵니다.
html파일은 <meta charset="UTF-8">로 작성했습니다
javascript랑 php를 읽을 줄을 몰라서 다른 질문들을 참고해서는 수정을 할 수가 없습니다 ㅠㅠ
익스텐션을 써서 만들어진 php파일 코드입니다. 길어서 죄송합니다. 부디 어디를 고치면 될지 아시는 분은 답변 부탁드립니다!!
<?
// SMTP Params
global $gSMTPServer, $gSMTPLogin, $gSMTPPassword, $gEmailto, $gTestCaptcha, $gOKMessage;
$gSMTPServer = "";
$gSMTPLogin = "";
$gSMTPPassword = "";
$gEmailto = "qdesign@hanmail.net";
$gTestCaptcha = false;
$gOKMessage = "Success! Your Email has been sent.";
?>
<?
session_start();
function ShowMessage($msg) {
echo '<div align="center">';
echo $msg;
echo '<br><br><a href="javascript: history.back()"><- Go to previous page></a>';
echo '</div>';
}
function ShowMessageRef($msg) {
echo '<div align="center">';
echo $msg;
echo '<br><br><a href="'.$_SERVER['HTTP_REFERER'].'"><- Go to previous page></a>';
echo '</div>';
}
function SMTPmail($server, $login, $password, $emailto, $subject, $message, $from) {
function get_data($smtp_conn)
{
$data="";
while($str = @fgets($smtp_conn,515))
{
$data .= $str;
if(substr($str,3,1) == " ") { break; }
}
return $data;
}
$headers = "To: $emailto\nFrom: $from\nSubject: $subject\nX-Mailer: The Bat! (v3.99.3) Professional\n";
$smtp_conn = @fsockopen($server, 25, &$errno, &$errstr, 30);
if (!$smtp_conn) {
return "Server $server. Connection failed: $errno";
}
$data = get_data($smtp_conn);
$serverdomainarray = explode('.', $server);
$serverdomainarraycount = count($serverdomainarray);
$serverdomain = $serverdomainarray[$serverdomainarraycount - 2].".".$serverdomainarray[$serverdomainarraycount - 1];
fputs($smtp_conn,"HELO $serverdomain\r\n");
$data = get_data($smtp_conn);
if($data != 250) {fclose($smtp_conn); return 'SMTP server HELO command error.';}
fputs($smtp_conn,"AUTH LOGIN\r\n");
$data = get_data($smtp_conn);
if($data != 334) {fclose($smtp_conn); return 'SMTP server AUTH command error.';}
fputs($smtp_conn,base64_encode($login)."\r\n");
$data = get_data($smtp_conn);
if($data != 334) {fclose($smtp_conn); return 'SMTP server login failed.';}
fputs($smtp_conn,base64_encode($password)."\r\n");
$data = get_data($smtp_conn);
if($data != 235) {fclose($smtp_conn); return 'SMTP server incorrect password.';}
fputs($smtp_conn,"MAIL FROM: $login@$serverdomain\r\n");
$data = get_data($smtp_conn);
if($data != 250) {fclose($smtp_conn); return 'SMTP server MAILFROM command error.';}
fputs($smtp_conn,"RCPT TO: $emailto\r\n");
$data = get_data($smtp_conn);
if($data != 250) {fclose($smtp_conn); return 'SMTP server RCPT TO command error.';}
fputs($smtp_conn,"DATA\r\n");
$code = substr(get_data($smtp_conn),0,3);
if($code != 354) {fclose($smtp_conn); return 'SMTP server DATA sending error.';}
fputs($smtp_conn,$headers."\r\n".$message."\r\n.\r\n");
$code = substr(get_data($smtp_conn),0,3);
if($code != 250) {fclose($smtp_conn); return 'SMTP server HEADER sending error.';}
fputs($smtp_conn,"\n.\nQUIT\n");
$data = get_data($smtp_conn);
fclose($smtp_conn);
return 'OK';
}
// PHPMailer
function CallPHPMailer($sendmethod) {
global $gTestCaptcha;
if (($gTestCaptcha == true)&&(empty($_POST['captcha']) || ($_POST['captcha'] != $_SESSION['random_number']))) {
ShowMessage('ERROR!<br>Verification code is incorrect.');
exit();
}
if (empty($_POST['cname'])) {
ShowMessage('ERROR!<br>Enter correct name.');
exit();
}
if (empty($_POST['email']) || !preg_match("/^[-\w.]+@([A-z0-9][-A-z0-9]+\.)+[A-z]{2,4}$/", $_POST['email'])) {
ShowMessage('ERROR!<br>Enter correct email.');
exit();
}
$cname = substr($_POST['cname'], 0, 50);
$cname = trim($cname);
$cname = htmlspecialchars(stripslashes($cname));
$email = substr($_POST['email'], 0, 50);
$email = trim($email);
$email = htmlspecialchars(stripslashes($email));
$subject = substr($_POST['subject'], 0, 50);
$subject = trim($subject);
$subject = htmlspecialchars(stripslashes($subject));
$message = substr($_POST['message'], 0, 4096);
$message = trim($message);
$message = htmlspecialchars(stripslashes($message));
global $gSMTPServer, $gSMTPLogin, $gSMTPPassword, $gEmailto, $gOKMessage;
if ($sendmethod == 'sendmail') {
if (mail($gEmailto, $subject, $message, 'From: "'.$cname.'" <'.$email.'>')) {
ShowMessageRef($gOKMessage);
} else {
ShowMessageRef('Error during message sending.');
}
} else if ($sendmethod == 'SMTP') {
$result = SMTPmail($gSMTPServer, $gSMTPLogin, $gSMTPPassword, $gEmailto, $subject, $message, 'From: "'.$cname.'" <'.$email.'>');
if ($result == 'OK') {
ShowMessageRef($gOKMessage);
} else {
ShowMessageRef($result);
}
}
}
// AjaxMailer
function CallAJAXMailer($sendmethod) {
function MakeExit($vsStatus, $vsErrors) {
header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
echo '<resultset>';
echo '<status>'.$vsStatus.'</status>';
if ($vsErrors <> '') {
echo '<errors>'.$vsErrors.'</errors>';
}
echo '</resultset>';
exit();
}
function cleanPosUrl ($str) {
$nStr = $str;
$nStr = str_replace("**am**","&",$nStr);
$nStr = str_replace("**pl**","+",$nStr);
$nStr = str_replace("**eq**","=",$nStr);
return stripslashes($nStr);
}
$cname = substr(cleanPosUrl($_POST['posName']), 0, 50);
$cname = trim($cname);
$cname = htmlspecialchars(stripslashes($cname));
$email = substr(cleanPosUrl($_POST['posEmail']), 0, 50);
$email = trim($email);
$email = htmlspecialchars(stripslashes($email));
$subject = substr(cleanPosUrl($_POST['posSubject']), 0, 50);
$subject = trim($subject);
$subject = htmlspecialchars(stripslashes($subject));
$message = substr(cleanPosUrl($_POST['posMessage']), 0, 4096);
$message = trim($message);
$message = htmlspecialchars(stripslashes($message));
$captcha = substr(cleanPosUrl($_POST['posCaptcha']), 0, 50);
$captcha = trim($captcha);
$captcha = htmlspecialchars(stripslashes($captcha));
$posErrors = '';
global $gTestCaptcha;
if (($gTestCaptcha == true)&&(empty($captcha) || ($captcha != $_SESSION['random_number']))) {
$posErrors .= '<li>Verification code is incorrect!</li>';
$posErrors = '<![CDATA['.$posErrors.']]>';
MakeExit('CAPTCHAERROR', $posErrors);
}
if (empty($cname)) {
$posErrors .= '<li>Enter correct name</li>';
}
if (empty($email) || !preg_match("/^[-\w.]+@([A-z0-9][-A-z0-9]+\.)+[A-z]{2,4}$/", $email)) {
$posErrors .= '<li>Enter correct email</li>';
}
if ($posErrors <> '')
$posErrors = '<![CDATA['.$posErrors.']]>';
if ($posErrors <> '')
MakeExit('ERRORS', $posErrors);
global $gSMTPServer, $gSMTPLogin, $gSMTPPassword, $gEmailto;
if ($sendmethod == 'sendmail') {
if (mail($gEmailto, $subject, $message, 'From: "'.$cname.'" <'.$email.'>')) {
MakeExit('OK', '');
} else {
MakeExit('NOTOK', '');
}
} else if ($sendmethod == 'SMTP') {
$result = SMTPmail($gSMTPServer, $gSMTPLogin, $gSMTPPassword, $gEmailto, $subject, $message, 'From: "'.$cname.'" <'.$email.'>');
if ($result == 'OK') {
MakeExit('OK', '');
} else {
MakeExit('ERRORS', '<![CDATA[<li>'.$result.'</li>]]>');
}
}
}
// Main
if (isset($_GET['action']))
if ($_GET['action'] == 'getCaptcha') {
header('Pragma: no-cache');
header('Expires: -1');
header('Cache-control: no-cache');
$_SESSION['random_number']=rand(1000, 9999);
$number=$_SESSION['random_number'];
header ("Content-type: image/png");
$im = @imagecreatetruecolor(60, 19)
or die("Cannot Initialize new GD image stream");
$text_color = imagecolorallocate($im, 199, 224, 212);
$text_color1 = imagecolorallocate($im, 0, 0, 0);
$background = imagecolorallocate($im, 121, 179, 11);
$e=imagefilledrectangle ( $im, 0, 0,100, 50, $background);
imagestring($im, 8, 2, 2, $number, $text_color);
imagestring($im, 8, 4, 4, $number, $text_color1);
imagegif($im);
imagedestroy($im);
exit();
}
if (isset($_GET['tech']) && isset($_GET['method'])) {
if ($_GET['tech'] == 'php') {
CallPHPMailer($_GET['method']);
} else if ($_GET['tech'] == 'ajax') {
CallAJAXMailer($_GET['method']);
}
}
?>