我正在开发一个massmail 脚本,该脚本向特定数据库中存在的每个电子邮件ID 发送一封电子邮件。但是有一些问题。
就像我有以下数据库:
id email link
1 a@bc.com bc.com
2 b@cd.com cd.com
并假设邮件内容是:'Testing this script'
脚本完美地向 a@bc.com 发送电子邮件,但第二次发送电子邮件时,即发送到 b@cd.com,内容会翻倍。
我的意思是第二个收件人收到这样的电子邮件:
测试这个脚本
测试这个脚本
第三个收件人收到一封内容重复三次的电子邮件,第四个收件人收到了四次,以此类推。
该脚本从数据库中的电子邮件字段中获取电子邮件地址并向其发送电子邮件。
我的代码:
<?
include "header.php";
include "config2.php";
$subject="Massmail";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
mysql_connect($server, $db_user, $db_pass)
or die ("Database CONNECT Error");
$resultquery = mysql_db_query($database, "select * from $table");
while ($query = mysql_fetch_array($resultquery))
{
$mailto=$query[$table_email];
$domain=$query[$table_link];
$domain2 = str_replace(array('http://','HTTP://','Http://'), '',$domain);
$handle = fopen("http://$domain2","r") or die("Unable to open link ( $domain ). <a href='javascript:history.go(-1);'>Go back</a> and please try again ");
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192);
$contents = str_replace('window.location = "/abc.html"','window.location = ""',$contents);
$contents = mb_convert_encoding($contents, "HTML-ENTITIES", "auto");
}
$i = md5(uniqid(rand(), true)) . '.' . html;
$fh = fopen("/home/host/public_html/content/$i", "w");
fwrite($fh, $contents);
fclose($fh);
$filename = '/files/$i';
$message1 .= "Testing Mail Script Version 2";
mail($mailto, $subject, $message1, $headers, "-f" . 'noreply@domain.com');
echo 'Mail sent to '.$mailto.'<br>';
sleep($seconds);
}
include "footer.php";
?>
我试图回显必须发送的邮件,我得到了这个:
To: a@bc.com
Subject: Massmail
Message:
Testing mail script
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
to: b@cd.com
Subject: Massmail
Message:
Testing mail scriptTesting mail script
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
对你的帮助表示感谢。提前致谢