-2

以下のコードを使用して、データベースから多くの人に電子メールを送信しますが、通常はタイムアウトになり、すべての人に送信されるわけではありません。PHPで10分あたりわずか1000通のメールを送信するようにPHPで設定するにはどうすればよいですか?

require_once "Mail.php";

$from = "xxx Support <$sender>";
$to = "$to";
$subject = "$subject";
$body = "Dear $fname,\n\n$note\n\n\nYou are getting this email because you registered on our website www.xxx.com and agreed to our Terms and Conditions which includes to receive email from us at any time to your email address $to.";

$host = "smtp1.xxx.net";
$username = "no_reply@xxx.net";
$password = "4t46546$#@?";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
}

// Show sent emails.
echo "$row[fname] $row[lname] ($row[email])<br>";
}
4

1 に答える 1

0

スクリプトを変更して、特定の数から開始して受信者を取得し、すべての受信者がサービスを受けるまで META リダイレクトを出力して、ブラウザを中断したところから強制的にリロードすることができます。

想像:

<?php
// Start from $x, or zero if no $x
$x = ( isset( $_REQUEST['x'] ) ? $_REQUEST['x'] : 0 ); 

// Count total number of recipients
$rs = mysql_query('SELECT COUNT(*) AS total FROM recipients ');  
if ( $rs ) $row = mysql_fetch_assoc( $rs );
$total = $row['total'];

// Pull recipients $x through $x+1000 from database  
$rs = mysql_query('SELECT * FROM recipients ORDER BY email ASC LIMIT ' . $x . ', 1000 ' );
// Count number of recipients in query result set
$num_recipients = mysql_num_rows( $rs ); 

while ( $row = mysql_fetch_assoc( $rs ) ){
    // Send the message here...
}

if ( ( $num_recipients + $x) < $total ){
    // We've not yet reached the total # of recipients
    // Output the meta redirect to start from ($x+1000).
    echo '<meta http-equiv="REFRESH" content="0;url=this-script.php?x=' . ($x+1000) . '">';
} else {
    // We've finished, do something...
}
于 2012-08-13T03:09:01.287 に答える