-=[ Mr. Bumblebee ]=-
_Indonesia_
<?php
class Sendmail
{
/*
* ¸ÞÀϹ߼ÛÀ» À§ÇÑ Å¬·¡½º
* ¿ÜºÎ SMTP ¼¹ö¸¦ Áö¿øÇÕ´Ï´Ù.
* Author: Gwangsoo, Ryu (piver@ineemail.com)
*/
var $UseSMTPServer = false; // ´Ù¸¥ SMTP ¼¹ö¸¦ ÀÌ¿ëÇÒ °æ¿ì
var $SMTPServer; // SMTP ¼¹ö µµ¸ÞÀÎ
var $SMTPPort = 25; // Port
var $SMTPAuthUser; // SMTP ÀÎÁõ »ç¿ëÀÚ
var $SMTPAuthPasswd; // SMTP ÀÎÁõ ºñ¹Ð¹øÈ£
var $Socket;
var $MailHeaderArray = array(); // ¸ÞÀÏÇì´õ¸¦ ´ãÀ» ¹è¿
var $MailFrom; // º¸³»´Â »ç¶÷
var $ReplyTo; // ȸ½Å¹ÞÀ» ÁÖ¼Ò (±âº»ÀûÀ¸·Î º¸³»´Â ¸ÞÀÏÁÖ¼Ò°¡ µÈ´Ù)
var $MailTo = array(); // ¹Þ´Â »ç¶÷À» ´ãÀ» ¹è¿
var $Subject; // ¸ÞÀÏÁ¦¸ñ
var $MailBody; // ¸ÞÀϺ»¹®
var $Charset = 'EUC-KR'; // ¸ÞÀϱ⺻ ij¸¯ÅͼÂ
var $Attach = array(); // ÀÎÄÚµùµÈ ÷ºÎÆÄÀÏ
var $Boundary; // Bound
function __construct($charset = 'EUC-KR')
{
$this->Boundary = md5(uniqid(microtime())); // ¹Ù¿îµå¸¦ ÃʱâÈÇÑ´Ù
if(!empty($charset)) $this->Charset = $charset; // ij¸¯ÅͼÂ
}
function setFrom($email, $name = null)
{
// º¸³»´Â ¸ÞÀÏ
$this->setReplyTo($email);
return $this->MailFrom = ($name) ? $name . ' <' . $email . '>' : $email;
}
function setReplyTo($email)
{
// ȸ½ÅÁÖ¼Ò - ±âº»ÀûÀ¸·Î º¸³»´Â ¸ÞÀÏÀ» ȸ½ÅÁÖ¼Ò·Î ¼ÂÇÑ´Ù
return $this->ReplyTo = $email;
}
function setSubject($Subject)
{
// Á¦¸ñ
return $this->Subject = $Subject;
}
function addTo($email, $name = null)
{
// ¹Þ´Â ¸ÞÀÏÀ» Ãß°¡ÇÑ´Ù
return $this->MailTo[$name] = $email;
}
function addAttach($Filename, $Source)
{
// ÷ºÎÆÄÀÏÀ» Ãß°¡ÇÑ´Ù
$fp = fopen($Source, 'r'); // ¼Ò½ºÆÄÀÏÀ» ¿¬´Ù
if($fp) {
$fBody = fread($fp, filesize($Source)); // ÆÄÀÏÀÇ ³»¿ëÀ» Àоî¿Â´Ù
@fclose($fp);
$this->Attach[$Filename] = $fBody; // Attach ¹è¿¿¡ ´ã´Â´Ù
}
}
function setMailBody($Body, $useHtml = true)
{
if(!$useHtml) { // ¸ÞÀϺ»¹®ÀÌ HTML Çü½ÄÀÌ ¾Æ´Ï¸é HTML Çü½ÄÀ¸·Î ¹Ù²Ù¾îÁØ´Ù
$Body = '
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=' . $this->Charset . '">
<style type="text/css">
BODY, TH, TD, DIV, SPAN, P, INPUT {
font-size:12px;
line-height:17px;
}
BODY, DIV { text-align:justify; }
</style>
</head>
<body>
' . nl2br($Body) . '
</body>
</html>
';
}
$this->MailBody = $Body; // ¸ÞÀϺ»¹®À» ¼ÂÇÑ´Ù
}
function AddBasicHeader()
{
// ¸ÞÀÏÀÇ ±âº» Çì´õ¸¦ ÀÛ¼ºÇÑ´Ù
$this->addHeader('From', $this->MailFrom);
$this->addHeader('User-Agent', 'Dabuilder Mail System');
$this->addHeader('X-Accept-Language', 'ko, en');
$this->addHeader('X-Sender', $this->ReplyTo);
$this->addHeader('X-Mailer', 'PHP');
$this->addHeader('X-Priority', 1);
$this->addHeader('Reply-to', $this->ReplyTo);
$this->addHeader('Return-Path', $this->ReplyTo);
if(count($this->Attach) > 0) { // ÷ºÎÆÄÀÏÀÌ ÀÖÀ» °æ¿ìÀÇ Çì´õ
$this->addHeader('MIME-Version', '1.0');
$this->addHeader('Content-Type', 'Multipart/mixed; boundary = "' . $this->Boundary . '"');
} else { // ÷ºÎÆÄÀÏÀÌ ¾ø´Â ÀÏ¹Ý ¸ÞÀÏÀÏ °æ¿ìÀÇ Çì´õ
$this->addHeader('Content-Type', 'text/html; charset=' . $this->Charset);
$this->addHeader('Content-Transfer-Encoding', '8bit');
}
}
function addHeader($Content, $Value)
{
// ¸ÞÀÏÇì´õÀÇ ³»¿ëÀ» Ãß°¡ÇÑ´Ù
$this->MailHeaderArray[$Content] = $Value;
}
function MailAttach()
{
// ÷ºÎÆÄÀÏÀÌ ÀÖÀ» °æ¿ì ¸ÞÀϺ»¹®¿¡ ÷ºÎÆÄÀÏÀ» µ¡ºÙÀδÙ
$arrRet = array();
if(count($this->Attach) > 0) {
foreach($this->Attach as $Filename => $fBody) {
$tmpAttach = "--" . $this->Boundary . "\r\n";
$tmpAttach .= "Content-Type: application/octet-stream\r\n";
$tmpAttach .= "Content-Transfer-Encoding: base64\r\n";
$tmpAttach .= "Content-Disposition: attachment; filename=\"" . $Filename . "\"\r\n\r\n";
$tmpAttach .= $this->encodingContents($fBody) . "\r\n\r\n";
$arrRet[] = $tmpAttach;
}
}
return implode('', $arrRet);
}
function setUseSMTPServer($boolean = null)
{
// ¿ÜºÎ SMTP ¼¹ö¸¦ ÀÌ¿ëÇÒ °ÍÀÎÁö¸¦ ¼ÂÇÑ´Ù
return (is_null($boolean)) ? $this->UseSMTPServer : $this->UseSMTPServer = $boolean;
}
function setSMTPServer($smtpServer = null, $port = 25)
{
// ¿ÜºÎ SMTP ¼¹ö¸¦ ÀÌ¿ëÇÒ °æ¿ì SMTP ¼¹ö¸¦ ¼³Á¤ÇÑ´Ù
$this->SMTPPort = $port;
return (is_null($smtpServer)) ? $this->SMTPServer : $this->SMTPServer = $smtpServer;
}
function setSMTPUser($User = null)
{
// ¿ÜºÎ SMTP ¼¹ö¸¦ ÀÌ¿ëÇÒ °æ¿ì ·Î±×ÀÎ »ç¿ëÀÚ¸¦ ¼³Á¤ÇÑ´Ù
return (is_null($User)) ? $this->SMTPAuthUser : $this->SMTPAuthUser = $User;
}
function setSMTPPasswd($Passwd = null)
{
// ¿ÜºÎ SMTP ¼¹ö¸¦ ÀÌ¿ëÇÒ °æ¿ì ·Î±×ÀÎ ºñ¹Ð¹øÈ£¸¦ ¼³Á¤ÇÑ´Ù
return (is_null($Passwd)) ? $this->SMTPAuthPasswd : $this->SMTPAuthPasswd = $Passwd;
}
function encodingContents($contets)
{
// ¸ÞÀϺ»¹®À» ÀÎÄÚµùÇÏ´Â ¿ªÇÒÀ» ÇÑ´Ù
return chunk_split(base64_encode($contets));
}
function makeMailHeader()
{
// º¸³¾ ¸ÞÀÏÀÇ Çì´õ¸¦ ÀÛ¼ºÇÑ´Ù
$header = "";
foreach($this->MailHeaderArray as $Key => $Val)
$header .= $Key . ": " . $Val . "\n";
return $header . "\r\n";
}
function send()
{
// ¸ÞÀÏÀ» Àü¼ÛÇÑ´Ù
$this->AddBasicHeader(); // ¸ÞÀÏÀÇ ±âº»Çì´õ¸¦ »ý¼ºÇÑ´Ù
if($this->UseSMTPServer) return $this->_SMTPSend(); // ¿ÜºÎ SMTP ¼¹ö¸¦ ÀÌ¿ëÇÒ °æ¿ì
else return $this->_localSend(); // ·ÎÄà SMTP ¸¦ ÀÌ¿ëÇÒ °æ¿ì
}
function _SMTPSend()
{
/*
* ¿ÜºÎ SMTP ¼¹ö¸¦ ÀÌ¿ëÇÒ °æ¿ì ¼ÒÄÏÁ¢¼ÓÀ» ÅëÇØ¼ ¸ÞÀÏÀ» Àü¼ÛÇÑ´Ù
*/
$Succ = 0;
if($this->SMTPServer) {
$this->addHeader('Subject', $this->Subject); // ¸ÞÀÏÇì´õ¿¡ Á¦¸ñÀ» Ãß°¡ÇÑ´Ù
$MailBody = $this->makeMailBody(); // ¸ÞÀϺ»¹®À» »ý¼ºÇÑ´Ù
if(count($this->MailTo) > 0) { // ¹Þ´Â ¸ÞÀÏÀÌ ÀÖÀ¸¸é ´ÙÀ½ ÀÛ¾÷À» ¹Ýº¹ÇÑ´Ù
foreach($this->MailTo as $Name => $Email) {
$mailTo = ($Name) ? $Name . ' <' . $Email . '>' : $Email; // ¹Þ´Â»ç¶÷
$this->addHeader('To', $mailTo); // ¸ÞÀÏÇì´õ¿¡ ¹Þ´Â»ç¶÷À» Ãß°¡ÇÑ´Ù
$Contents = $this->makeMailHeader() . "\r\n" . $MailBody; // ¸ÞÀÏÇì´õ¿Í º»¹®À» ÀÌ¿ëÇØ Àü¼ÛÇÒ ¸ÞÀÏÀ» »ý¼ºÇÑ´Ù
$this->Socket = fsockopen($this->SMTPServer, $this->SMTPPort); // ¼ÒÄÏÁ¢¼ÓÇÑ´Ù
if($this->Socket) {
$this->_sockPut('HELO ' . $this->SMTPServer);
if($this->SMTPAuthUser) { // SMTP ÀÎÁõ
$this->_sockPut('AUTH LOGIN');
$this->_sockPut(base64_encode($this->SMTPAuthUser));
$this->_sockPut(base64_encode($this->SMTPAuthPasswd));
}
$this->_sockPut('MAIL From:' . $this->ReplyTo); // º¸³»´Â ¸ÞÀÏ
$this->_sockPut('RCPT To:' . $Email); // ¹Þ´Â¸ÞÀÏ
$this->_sockPut('DATA');
$this->_sockPut($Contents); // ¸ÞÀϳ»¿ë
$Result = $this->_sockPut('.'); // Àü¼Û¿Ï·á
if(strpos($Result, 'Message accepted for delivery') !== false) $Succ++; // ¼º°ø¿©ºÎÆÇ´Ü
$this->_sockPut('QUIT'); // Á¢¼ÓÁ¾·á
}
}
}
} else $Succ = $this->_localSend(); // ¿ÜºÎ SMTP ¼¹ö¸¦ ÀÌ¿ëÇÏÁö ¾ÊÀ¸¸é ·ÎÄà SMTP¸¦ ÀÌ¿ëÇØ¼ Àü¼ÛÇÑ´Ù
return $Succ;
}
function _sockPut($str)
{
// ¼ÒÄÏÁ¢¼Ó½Ã ³»¿ëÀü¼Û ¹× °á°ú°ª ¹Þ±â
@fputs($this->Socket, $str . "\r\n");
return @fgets($this->Socket, 512);
}
function _localSend()
{
$Contents = $this->makeMailBody(); // ¸ÞÀϺ»¹®À» ÀÛ¼ºÇÑ´Ù
$Succ = 0;
foreach($this->MailTo as $Name => $Email) {
$toMail = ($Name) ? $Name . ' <' . $Email . '>' : $Email; // ¹Þ´Â¸ÞÀÏ
$this->addHeader('To', $toMail); // ¸ÞÀÏÇì´õ¿¡ ¹Þ´Â¸ÞÀÏÀ» Ãß°¡ÇÑ´Ù
$header = $this->makeMailHeader(); // Çì´õ¸¦ ÀÛ¼ºÇÑ´Ù
if(mail($Email, $this->Subject, $Contents, $header)) $Succ++; // ¼º°ø¿©ºÎ ÆÇ´Ü
}
return $Succ;
}
function makeMailBody()
{
// ¸ÞÀÏÀÇ º»¹®À» ÀÛ¼ºÇÑ´Ù
$mailbody = "";
if(count($this->Attach) > 0) { // ÷ºÎÆÄÀÏÀÌ ÀÖÀ» °æ¿ì º»¹®À» ÀÎÄÚµùÇÏ¿© ¸¸µç´Ù
$mailbody .= "--" . $this->Boundary . "\r\n";
$mailbody .= "Content-Type: text/html; charset=" . $this->Charset . "\r\n";
$mailbody .= "Content-Transfer-Encoding: base64\r\n\r\n";
$mailbody .= $this->encodingContents($this->MailBody) . "\r\n\r\n";
$mailbody .= "\r\n" . $this->MailAttach();
} else $mailbody = $this->MailBody; // ÷ºÎÆÄÀÏÀÌ ¾øÀ¸¸é ±×³É HTML Çü½ÄÀ¸·Î ¸ÞÀϺ»¹®À» »ý¼ºÇÑ´Ù
return $mailbody;
}
}
?>
Copyright © 2017 || Recoded By Mr.Bumblebee