2011-08-13 5 views
0

나는 다음을 사용하여 데이터베이스에있는 사람에게 이메일을 보냈습니다. 문제는 데이터베이스에 500 개 이상의 회원이 있으며 스크립트가 느려지고 TO : 입력란에 각 회원 이메일 주소가 표시된다는 것입니다. 대신 다른 사이트에서 BCC를 사용하라는 제안을 시도했지만 전자 메일을 개별적으로 보내려면이 방법을 사용하지 않는 것이 아닌지 궁금합니다.SQL 실행 목록의 전자 메일 목록

$sql = "SELECT * FROM users WHERE system = '101' AND mailing_list = 'yes'"; 
$result = mysql_query($sql) or die("Unable to execute<br />$sql<br />".mysql_error()); 
$row = mysql_fetch_array($result); 
var_dump($row); 
$to .= $row['email'] . "\r\n"; 
//send email 

답변

1

PHP의 메일(), 나는 설명서에서 phpmailer

같은 것을 매우 비효율적 사용하는 것이 좋습니다된다

참고 :

그것은 주목할 가치가 그 메일() 함수는 더 큰 전자 메일 볼륨에 적합하지 않습니다. 이 함수는 각 전자 메일에 대해 SMTP 소켓을 열고 닫습니다. 이는 그리 효율적이지 않습니다.

많은 양의 이메일을 보내려면»PEAR :: Mail 및» PEAR :: Mail_Queue 패키지를 참조하십시오.

0

PHPMailer는이 상황에서만 사용되기 때문에 사용해야합니다. mail() 문제는 각 이메일 이후에 연결을 열고 닫는 것입니다. 분명히 1 개의 연결을 열고, 모든 전자 메일을 하나씩 보내고 연결을 닫으려고합니다.

뭔가 below 같은 :

require("class.phpmailer.php"); 

$mail = new phpmailer(); 

$mail->From  = "[email protected]"; 
$mail->FromName = "List manager"; 
$mail->Host  = "smtp1.example.com;smtp2.example.com"; 
$mail->Mailer = "smtp"; 

@MYSQL_CONNECT("localhost","root","password"); 
@mysql_select_db("my_company"); 
$query = "SELECT full_name, email, photo FROM employee WHERE id=$id"; 
$result = @MYSQL_QUERY($query); 

while ($row = mysql_fetch_array ($result)) 
{ 
    // HTML body 
    $body = "Hello <font size=\"4\">" . $row["full_name"] . "</font>, <p>"; 
    $body .= "<i>Your</i> personal photograph to this message.<p>"; 
    $body .= "Sincerely, <br>"; 
    $body .= "phpmailer List manager"; 

    // Plain text body (for mail clients that cannot read HTML) 
    $text_body = "Hello " . $row["full_name"] . ", \n\n"; 
    $text_body .= "Your personal photograph to this message.\n\n"; 
    $text_body .= "Sincerely, \n"; 
    $text_body .= "phpmailer List manager"; 

    $mail->Body = $body; 
    $mail->AltBody = $text_body; 
    $mail->AddAddress($row["email"], $row["full_name"]); 
    $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg"); 

    if(!$mail->Send()) 
     echo "There has been a mail error sending to " . $row["email"] . "<br>"; 

    // Clear all addresses and attachments for next loop 
    $mail->ClearAddresses(); 
    $mail->ClearAttachments(); 
} 
관련 문제