티스토리 뷰

Language/PHP

Mail

MiniNeko 2015. 11. 29. 04:09

★ 메일 확인테스트는 hanmail 로 하는게 조금 좋은듯함. 

■ 발송


// 메일발송 시작 ##############################
// 보내는 사람
$txtFromName = "ppoppo";
$txtFromEmail = "ppoppo@hanmail.net"; 
// 받는 사람
$txtToName = $rowData['NAME'];
$txtToEmail = $rowData['EMAIL'];
// 제목
$txtTitle = "PPOPPO 에 확인 요청한 아이디입니다.";
// 내용
$txtContents = $rowData['MID'];
include $_SERVER['DOCUMENT_ROOT']."login/sendMail.php";
// 메일발송 끝 ##############################



■ sendMail.php


< ?
/*
function strCodeUTF8($str) {
      $str = iconv("SJIS","UTF-8",$str);
      return $str;
}
*/
function dateFormatHandler($str) {
   $strTemp = "";
   $strTemp = substr($str,0,4)."-".substr($str,4,2)."-".substr($str,6,2)." ".substr($str,8,2).":".substr($str,10,2).":".substr($str,12,2);
   return $strTemp;
}

$dateTemp = date('Ymdhis',time());
$dateTemp = dateFormatHandler($dateTemp);



$charset = "UTF-8";
$boundary = uniqid(rand(),true);

$mail_array[from_name] = $txtFromName;
$mail_array[from_email] = $txtFromEmail;

$mail_array[to_name] = $txtToName;
$mail_array[to_email] = $txtToEmail;

$titleTemp = $txtTitle." [ ".$dateTemp." ]";
//$titleTemp = strCodeUTF8($titleTemp);
$mail_array[title] = $titleTemp;

$contentTemp = "
아이디 확인입니다.<br />
< br />
등록된 회원의 아이디 정보는 다음과 같습니다.<br />
< br />
--------------------------------------------------------------------------------<br />
아이디:$txtContents <br />
--------------------------------------------------------------------------------<br />
< br />
";
//$contentTemp = strCodeUTF8($contentTemp);
$mail_array[content] = <<<MSG
< html>
< head>
< title>eMail</title>
< /head>
< body>
$contentTemp
< /body>
< /html>
MSG;

$mail_array[title] = '=?utf-8?b?'.base64_encode($mail_array[title]).'?=';
$mail_array[from_name] = '=?utf-8?b?'.base64_encode($mail_array[from_name]).'?=';
$mail_array[to_name] = '=?utf-8?b?'.base64_encode($mail_array[to_name]).'?=';
$recipient = $mail_array[to_name] . " <". $mail_array[to_email] . ">";

$headers =
"From: ". $mail_array[from_name] . " <".$mail_array[from_email] . ">
" .
"Return-Path: ".$mail_array[from_name] . " <" . $mail_array[from_email] . ">
" .
"Subject: ".$mail_array[title] . "
" .
"MIME-Version: 1.0
" .
"Content-Type: multipart/alternative; boundary="" . $boundary . """;

$body =
"--" . $boundary . "
".
"Content-Type: text/plain; charset=" . $charset . "; format=flowed
" .
"Content-Transfer-Encoding: base64
" .
"Content-Disposition: inline

" .
chunk_split(base64_encode(strip_tags($mail_array[content]))) . "

" .
"--" . $boundary . "
" .
"Content-Type: text/html; charset=" . $charset . "
" .
"Content-Transfer-Encoding: base64
" .
"Content-Disposition: inline

" .
chunk_split(base64_encode($mail_array[content]))."

" .
"--" . $boundary . "--
";

mail($recipient , $mail_array[title], $body, $headers);
?>


 
 
참고사항 : 붙여넣기 해서 오류가 뜨는 경우 줄바꿈 부분에 쓰레기 문자가 있는 경우가 있음. 
 
==================================================================================== 
 
 
 
■ mail 함수는 euc-kr 로 동작하는 것 같음 ( 추후 정확한 확인 요...)  
 
ob_start();
include "../../pg/login/pw_search_mail.php";
$html = ob_get_contents();
ob_end_clean(); 
 
$subjectMail = "[케이시시정공(주)] 임시비밀번호가 발급되었습니다.";
$subjectMail = iconv("UTF-8", "EUC-KR", $subjectMail);
$fromMail = "Content-type: text/html;charset=euc-kr
From: 케이시시정공(주) <info@kccpr.com>
Reply-to: info@kccpr.com";
$fromMail = iconv("UTF-8", "EUC-KR", $fromMail);
        
mail($email, $subjectMail, $html, $fromMail);  
 
-------------------------------------------------------------------------------------------------------------------------- 
[ pw_search_mail.php ]
<HTML>
< HEAD>
< TITLE>New Document</TITLE>
< meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
< LINK href="<?=$_SERVER[`HTTP_HOST`]?>/share/css/layout2.css">http://<?=$_SERVER[`HTTP_HOST`]?>/share/css/layout2.css" type=text/css rel=stylesheet>
< /HEAD>
< BODY>
< table cellpadding=0 cellspacing="0" border="0">
 <tr>
  <td>
   임시비밀번호가 아래와 같이 발급되었습니다.
   <br>로그인하셔서 비밀번호를 변경하세요.
   <br>임시 비밀번호: <span class="t09"><?=$total_r?></span>
   <br><br><a href="<?=$_SERVER[`HTTP_HOST`]?>/new/pages/sub04/sub04_06.php">http://<?=$_SERVER[`HTTP_HOST`]?>/new/pages/sub04/sub04_06.php" class="guide2" target="_blank">[로그인]</a>
  </td>
 </tr>
< /table>
< /BODY>
< /HTML> 
--------------------------------------------------------------------------------------------------------------------------
 
 
 
<? 
     $Name = "대보사"; //senders name
     $email = "administrators@daebosa.co.kr"; //senders e-mail adress
     $recipient = $Method[wMail]; //recipient
     $subject = $Method[wReTitle]; //subject
     $mail_body = $Method[wReNote]; //mail body
     $header = "From: ". $Name . " <" . $email . ">
"; //optional headerfields
     mail($recipient, $subject, $mail_body, $header); //mail command :)
?>
 
--------------------------------------------------------------------------------------------------------------------------
[ 기본 Source ]
 
< ?php
     $Name = "Da Duder"; //senders name
     $email = "email@adress.com"; //senders e-mail adress
     $recipient = "PersonWhoGetsIt@emailadress.com"; //recipient
     $mail_body = "The text for the mail..."; //mail body
     $subject = "Subject for reviever"; //subject
     $header = "From: ". $Name . " <" . $email . ">
"; //optional headerfields
     ini_set(`sendmail_from`, `me@domain.com`); //Suggested by "Some Guy"
     mail($recipient, $subject, $mail_body, $header); //mail command :)
?> 

'Language > PHP' 카테고리의 다른 글

문자열 공백제거 trim / preg_replace  (0) 2015.11.29
확장자 구하기  (0) 2015.11.29
[ MySQL ] mysql_insert_id() / last_insert_id() - RANK 최종값  (0) 2015.11.29
PHP + JSON 예제  (0) 2015.11.29
RSS - 사람인  (0) 2015.11.29
Total
Today
Yesterday
최근에 올라온 글
«   2025/01   »
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