I want to sent email to all enews subcribers but how can i send mail more than one person but when i used this coding its working not properly.it is send 3 times mails to one person
plz help me

<?php
// Connects to your Database 
include("connection.php");


?>





<link href="../log.css" rel="stylesheet" type="text/css" />


<?php
// Connects to your Database 
include("connection.php");


?>





<link href="../log.css" rel="stylesheet" type="text/css" />



<?php 


 
 //checks cookies to make sure they are logged in 

 if(isset($_COOKIE['ID_my_site'])) 

 { 

 	$username1 = $_COOKIE['ID_my_site']; 

 	$pass1 = $_COOKIE['Key_my_site']; 

 	 	$check = mysql_query("SELECT * FROM acl WHERE un = '$username1'")or die(mysql_error()); 

 	while($info = mysql_fetch_array( $check )) 	 

 		{ 

 

 //if the cookie has the wrong password, they are taken to the login page 

 		if ($pass1 != $info['password']) 

 			{ 			header("Location: index.php"); 

 			} 

 

 //otherwise they are shown the admin area	 

 	else 

 			{ 

 			 echo "<span class=\"he\"  style=\"color:#69B521;\"  >HI ".strtoupper("$username1</span> ");
			 echo $info['user_id']; 
 echo ' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <span class="bu" >
<a href="logout.php" style="text-decoration:none;">
 <input type="submit" name="submit" value="Login"></input> 
</a>
</span>'; 

?>


<?php
 			} 

 		} 






?>


<?php
 		} 

 else 

 

 //if the cookie does not exist, they are taken to the login screen 
 {			 

 header("Location: index.php"); 

 } 
 
 
 echo $check['ID']
 

 ?> 

  <table width="100%" border="0" id="alin">
    <tr  style="vertical-align:middle; text-align:left;">
    <form action="" name="myform" id="myform" method="post">

      <td width="16%" height="92"><span class="se"> PLese TYPE
            <textarea type="textarea" width="200px" height="200px" name="message" /> 
            </textarea>         </span>
</td>
<tr>
      <td width="84%"><span class="seb" >           <input type="submit" value="Submit" name="btn" />  </span>
</td>
</tr>
</form>
    </tr>
  </table>
  
  <?php
  
  if(isset($_POST["btn"]))
{
  
  	$selectadd=mysql_query("SELECT * FROM enew ");
		

	while($loopadd=mysql_fetch_array($selectadd))	
{
?>
  <table width="184" border="0">
    <tr width="200px">
      <td width="100px" height="50px" style="text-align:left; vertical-align:top;">
	  <p style="text-align:left;"><?php echo $loopadd['enew_id']; ?></p></td>

      <td width="100px" height="50px" style="text-align:left; vertical-align:top;">
	  <p style="text-align:left;"><?php echo $loopadd['enew_email']; ?></p></td>
      
            <td width="100px" height="50px" style="text-align:left; vertical-align:top;">
	  <p style="text-align:left;"><?php echo $loopadd['enew_user']; ?></p></td>
                  <td width="100px" height="50px" style="text-align:left; vertical-align:top;">
	  <p style="text-align:left;"><?php echo $_POST['message']; ?></p></td>
            <td width="100px" height="50px" style="text-align:left; vertical-align:top;">
     <?php 
$to =$loopadd['enew_email'];
$subject = "Test mail";
// Your message
$message=$_POST['message'];

$from="zohaib@sikone.com";
$sentmail = mail($to,$subject,$message,$from);
if($sentmail)
{
	echo ("send");
}
else
{
	echo ("Error");


}

?>
      
</td>      
    </tr>
  </table>

<?php 
}
  
}
else
{
	die ("Not SEnding") ;
}
  
  
  
      ?>

<?php


	
?>
  <p><br>
  <?php



?>

Dani AI

Generated

For : the symptom (one recipient getting the same message multiple times) most often comes from duplicate rows or the send loop iterating over the same address more than once. 's suggestion to echo the address inside the loop is a good first debug step — it will show whether the script is encountering the same email multiple times during one submission.

Quick checks and fixes:

  • Find duplicate addresses in the table with a grouped query:

    SELECT enew_email, COUNT(*) AS cnt
    FROM enew
    GROUP BY enew_email
    HAVING cnt > 1;

    If duplicates exist, either dedupe the table and add a UNIQUE index on the email column, or change the send query to return only distinct addresses.

  • Ensure the send loop uses distinct addresses (SELECT DISTINCT enew_email ...) or uses GROUP BY to guarantee one send per unique address.

Improve the mail call and delivery reliability:

  • Provide proper headers (From/Reply-To and Content-Type) instead of a raw email string in the headers parameter. For example:

    $headers  = "From: NoReply <no-reply@example.com>\r\n";
    $headers .= "Reply-To: support@example.com\r\n";
    $headers .= "Content-Type: text/plain; charset=UTF-8\r\n";
    mail($to, $subject, $message, $headers);
  • Consider switching to a library (PHPMailer, SwiftMailer) and sending via authenticated SMTP for better delivery and diagnostics.

Avoid accidental resends:

  • Use Post/Redirect/Get after sending (redirect and exit) so a page refresh does not resend messages.
  • Log the addresses actually sent to (file or DB) during a run to audit what was delivered.

Also check the form/markup for malformed tags (the textarea in the original post is malformed) and remove duplicate includes. These small fixes plus deduping the email source will usually stop multiple sends.

Recommended Answers

All 2 Replies

echo out your line 155 as follows and see the o/p.

echo $to =$loopadd['enew_email'];

my code is working but sending mail one person 3 times means one person getting mail more than one time plz rply me soon

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.