Daniel's Knowledge Storage

php 메일링을 단체로 반복해서 보내는 경우 풀소스 및 설명 본문

Develop/PHP

php 메일링을 단체로 반복해서 보내는 경우 풀소스 및 설명

다니엘SEO 2009. 8. 31. 06:17
<?
if(!$mode) {
include "connect.db";
set_time_limit(0); // 메일 발송 시간이 오래되는 경우 타임에러가 나지 않도록 php실행시간을 연장해준다.
//시작번호와 끝나는 번호는 메일링 테이블에서 no값입니다.
만약 1만명이 있으면 보통 1번부터 시작해서 3000번 보내고 다음번에는 3001번부터 보내시면 됩니다.

if(!$end_no){ $end_no = $start_no;}
if($start_no) $str = "where no>=$start_no and no <= $end_no";

// 모두에게 보내는 모드인 경우에는

if($to == "all") {
$result = mysql_query("select no, email from nan $str order by no");
}
$count = mysql_num_rows($result);

$Add = "Return-Path: $sendermail\n";
$Add .= "From: $sender <$sendermail>\nContent-Type:text/html\n";
$Add .= "ReplyTo: $sendermail\n";
$Add .= "Content-Type: text/html; charset=euc-kr\n";
$Add .= "Content-Transfer-Encoding: 8bit\r\n\r\n";

echo "<html><head><title>메일링 발송중....</title><META http-equiv='Content-Type' content='text/html; charset=euc-kr'></head><body>";

for($i=0; $i < $count; $i++) {
$no = mysql_result($result, $i, 0);
$email = mysql_result($result, $i, 1);
flush();
set_time_limit(100000);
if($email) {
$send=mail($email,stripslashes($subject),nl2br(stripslashes($content)),$Add);
echo (" <font color=blue>$no : $name(</font><font color=red>$email</font><font color=blue>)</font>님에게 메일을 보냈습니다.<br> ");

} else {
echo (" <font color=blue>$no : $name</font>님의 메일 정보가 없습니다.<br> ");
}

}

echo "총 <font color=red>$i</font>명에게 메일이 발송되었습니다.<br>";
$sender="";
$sendermail="";
// 변수를 초기화 해주는 것이 좋습니다.

echo "메일링 보내기가 정상적으로 완료되었습니다.<br>";
echo "<a href='?mode=close'>[닫기]</a>";
}
if($mode=="close") {
echo "<script>window.close()</script>";
}
?> 
Comments