간단한 php 클래스를 하나 만들었는데 메일이2번씩 보내 집니다.
본문
<?php
class SendMail {
private $to;
private $from;
private $subject;
private $message;
private $message_container = '';
private $headers;
public $result;
public function __construct(){
}
public function send($to, $from = '',$subject = '', $message = ''){
$this->to = $to;
$this->from = $from;
$this->subject = $subject;
$this->message = $message;
//메일 주소의 유효성 검사 및 보낼 주소가 여러개일경우 빈 공백 없애기.
if(mb_strpos($this->to, ",")){
$arr = explode(',', $this->to);
$str = '';
foreach ($arr as $key => $value) {
$arr[$key] = trim($value);
if(!$this->chekMailForm($value)) return FALSE;
}
$this->to = implode($arr, ',');
unset($arr);unset($str);
}else{//보낼 주소가 하나일 경우.
if(!$this->chekMailForm($this->to)) return FALSE;
}
if(!$this->chekMailForm($this->from)) return FALSE;
//헤더 작업
$this->headers = 'MIME-Version:1.0'."\r\n";
$this->headers .= 'Content-type: text/html; charset=euc-kr'."\r\n";
// echo "|||";
// echo $this->headers;
// echo "|||";
$this->headers .= "To:이재규원장님 <".$this->to.">\r\n";
$this->headers .= "From:해피본직원 <".$this->from.">\r\n";
//문자 깨짐 때문에 EUC-KR로 인코딩
$this->message_container = iconv('UTF-8', 'EUC-KR', $this->message_container);
$this->subject = iconv('UTF-8', 'EUC-KR', $this->subject);
$this->headers = iconv('UTF-8', 'EUC-KR', $this->headers);
//메일 보내기
mail($this->to, $this->subject, $this->message_container, $this->headers);
}
/*==메일 유효성 검사
* param
* - $email (str): 메일 주소.
* return: boolean
* ==*/
public function chekMailForm($email){
$_email = filter_var($email, FILTER_SANITIZE_EMAIL);
if(filter_var($_email, FILTER_VALIDATE_EMAIL)) return TRUE;
else return FALSE;
}
}
$mail = new SendMail();
$result = $mail->send('*** 개인정보보호를 위한 이메일주소 노출방지 ***', '*** 개인정보보호를 위한 이메일주소 노출방지 ***', '테스트문자', '안녕하세요');
?>
위 소스인데 희한하게 2번씩 날려 지네요. -_-;;
왜 2번씩 날아가는 건지 원인을 못찾고 있습니다.
!-->
답변을 작성하시기 전에 로그인 해주세요.