[英]Mass mail sends more than once to every mail
I have made a mass send mail function. 我做了一个批量发送邮件功能。 I have inserted 3 mails in the database but when I'm using mass mail function, mail sends more then 1 time to every email.
我在数据库中插入了3封邮件,但是当我使用群发邮件功能时,邮件向每封电子邮件发送的时间要多于1次。 I have tried to fix it but I couldn't.
我已尝试修复它,但无法解决。 I guess the problem is in the ending while loop.
我猜问题出在while循环的结尾。
Here is the code: 这是代码:
<html>
<form action="send_mass_mail.php" method="post">
<label>Subject of email:</label><br><input type="text" name="subject" id="subject"/><br>
<label>Body of email:</label><br><input type="textarea" name="body"></label><br>
<input type="submit" name="submit" value="Submit"/>
</form>
</html>
<?php
$user = "";
$password = "";
$host = "";
$dbase = "";
$table = "Mail";
$from= 'tjaabba.com@news.se';//specify here the address that you want email to be sent from
$subject= $_POST['subject'];
$body= $_POST['body'];
// Connection to DBase
mysql_connect($host,$user,$password)
or die("Unable to select database");
mysql_select_db('tjaabba_com');
$query= "SELECT * FROM $table";
$result= mysql_query ($query)
or die ('Error querying database.');
while ($row = mysql_fetch_array($result)) {
$email= $row['email'];
$msg= "Dear mail_form,\n$body";
if(isset($_POST['subject'])){
if(isset($_POST['submit'])){
mail($email, $subject, $body, 'From:' . $from);
echo 'Email sent to: ' . $email. '<br>';
}
}
}
?>
My guess is that it is in the while loop, but the best thing to do is try to debug the problem. 我的猜测是它处于while循环中,但是最好的办法是尝试调试问题。 You can do this using print_r() and die() functions.
您可以使用print_r()和die()函数执行此操作。
My suggestion would be to place this before the while loop to find out if you have duplicated data or it's some how coming out more than once. 我的建议是将其放置在while循环之前,以查找是否有重复的数据,或者这是多次出现的某种方式。
print_r(mysql_fetch_array($result));
die();
Then copy and paste what ever comes up on here, but replace the emails with dummy emails as we can then still get some sort of idea as to what is going on. 然后复制并粘贴这里发生的所有内容,但是将电子邮件替换为虚拟电子邮件,这样我们就可以对发生的事情有所了解。 Or maybe when you do this, you will get an idea as to what is going on.
或者,当您执行此操作时,您将对发生的事情有所了解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.