채택완료
간단한 php 클래스를 하나 만들었는데 메일이2번씩 보내 집니다.
Copy
<?phpclass 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('[email protected]', '[email protected]', '테스트문자', '안녕하세요');?>
위 소스인데 희한하게 2번씩 날려 지네요. -_-;;
왜 2번씩 날아가는 건지 원인을 못찾고 있습니다.
|
답변 1개 / 댓글 4개
채택된 답변
+20 포인트
불량학생™
2015-02-02 (월) 17:48:08
중간 중간에 echo 나 print로 찾으셔야 할듯
답변에 대한 댓글 4개
2015-02-02 (월) 17:52:23
답변을 작성하려면 로그인이 필요합니다.
근데 보내고 나면 2번 보내 지네요. -_-;;