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. I have tried to fix it but I couldn't. I guess the problem is in the ending while loop.
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>';
}
}
}
?>