Jump to content

Mass Email Problem


DCRepairs

Recommended Posts

Hi Guys,

 

I am about to rip my hair out after contstantly failing with this script.

Basically i have a table on my db with a list of email addresses in it.

 

And i have the below script which for soem reason when run is only sending the email to the top email address in the db. Any help would be really appreciated.

 

<?php

session_start();
$username = $_SESSION['username'];

include "dbconn.php";
include "functions.php";

$ipaddress=@$REMOTE_ADDR; 
$fullhost = gethostbyaddr($ipaddress);
$host = preg_replace("/^[^.]+./", "", $fullhost);

$query1  = "SELECT * FROM users where username='$username'";
$result1 = mysql_query($query1);

while($row1 = mysql_fetch_array($result1, MYSQL_ASSOC))
{

if($row1[userlevel]!='Admin'){
die ("Unauthorized Access.");
}
else
{
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

<link href="styles/main.css" rel="stylesheet" type="text/css" />
<link href="styles/topMenu.css" rel="stylesheet" type="text/css" />
<link href="styles/leftMenu.css" rel="stylesheet" type="text/css" />
<link href="styles/lightbox.css" rel="stylesheet" type="text/css" media="screen" />

<style type="text/css" media="print">


</style>


<meta name="description" content="DC Repairs is the only UK IT company offering computer repair services, web develoment and web hosting." />
<meta name="keywords" content="computer repairs,web development, computing,web hosting,apple,xerox,computing solutions,development solutions,Manchester, UK, Salford" />

<title>DC Repairs • Welcome</title>


</head>

<body>

<div id="wrapper">
<div id="header">
<a href="./index.php" class="imgLogo"><img src="images/header_logo.png" alt="DC Repairs" /></a>

<div id="topMenuContainer">
<div class="permLinks">
<strong>07951 520 538</strong>

<a href="logout.php" class="permLink">Logout ></a>
<a href="help.php" class="permLink" target="blank">Help ></a>
</div>
		<ul id="topMenu">
	<li><span class="topLevelMenu_MainSection"><a href="network.php">network tools</a></span>
	</li>
			<li><span class="topLevelMenu_MainSection"><a href="account.php">my account</a></span>
	</li>
	<li><span class="topLevelMenu_MainSection"><a href="support.php">support</a></span>
	</li>	
<?php

if($row1[userlevel]=='Admin'){
echo"
<ul>		
<li><span class='topLevelMenu_MainSection'><a href='admin.php'>admin area</a></span>
	</li>
"; 
}
else
{
}				
?>
</ul>
</div>
</div>
<div id="home_image">

	<img src="images/homeTop.gif" alt="...always thinking outside the box" title="...always thinking outside the box"  />
</div>

<br/><br/>
<table width='100%' border='0'>
<tr>
<td width='300'>
<strong>DC Repairs - Send Email</strong>
</td>
<td bgcolor='lightgrey'>
<?php echo "<strong>Username:</strong> $username            
<strong>IP Address:</strong> $ipaddress
           
$host
"; ?>
</td>
<td bgcolor='lightgrey'>
<a href='protected.php'><font size='1'>[HOME]</font></a>
</td>
</tr>
</table>
<br/>
<?php

if (isset($_POST['submit'])) {


$query2  = "SELECT email FROM mailinglist";
$result2 = mysql_query($query2);

while($row2 = mysql_fetch_array($result2, MYSQL_ASSOC))
{

$subject1= $_POST["subject"];
$message2= $_POST["desc"];

$message3 = nl2br("$message2");

////////SEND EMAIL

$today = date("F j, Y");

$to = $row2['email'];
$subject = $subject1;

$message ="
<html>
   <style type='text/css' media='screen'>
      body {
         background-color: #eeeeee;
      }

      a img {
         border: none;
      }

      table.bg1 {
         background-color: #eeeeee;
      }

      table.bg2 {
         background-color: #ffffff;
      }

      td.permission {
         background-color: #eeeeee;
         padding: 10px 20px 10px 20px;
      }

      td.permission p {
         font-family: Arial;
         font-size: 11px;
         font-weight: normal;
         color: #333333;
         margin: 0;
         padding: 0;
      }

      td.permission p2 {
         font-family: Arial;
         font-size: 8px;
         font-weight: normal;
         color: #333333;
         margin: 0;
         padding: 0;
      }

      td.permission p a {
         font-family: Arial;
         font-size: 11px;
         font-weight: normal;
         color: #333333;
      }

      td.body {
         padding: 0 20px 20px 20px;
         background-color: #ffffff;
      }

      td.sidebar h3 {
         font-family: Arial;
         font-size: 15px;
         font-weight: bold;
         color: #333333;
         margin: 0;
         padding: 0;
      }

      td.sidebar ul {
         font-family: Arial;
         font-size: 13px;
         font-weight: normal;
         color: #333333;
         margin: 6px 0 14px 24px;
         padding: 0;
      }

      td.sidebar ul li a {
         font-family: Arial;
         font-size: 13px;
         font-weight: normal;
         color: #680606;
      }

      td.sidebar h4 {
         font-family: Arial;
         font-size: 13px;
         font-weight: bold;
         color: #680606;
         margin: 6px 0 0 0;
         padding: 0;
      }

      td.sidebar h4 a {
         font-family: Arial;
         font-size: 13px;
         font-weight: bold;
         color: #680606;
         text-decoration: none;
      }

      td.sidebar p {
         font-family: Arial;
         font-size: 12px;
         font-weight: normal;
         color: #333333;
         margin: 0 0 10px 0;
         padding: 0;
      }

      td.sidebar p a {
         font-family: Arial;
         font-size: 12px;
         font-weight: normal;
         color: #680606;
         text-decoration: none;
      }

      td.buttons {
        padding: 20px 0 0 0; 
      }

      td.mainbar h2 {
         font-family: Arial;
         font-size: 16px;
         font-weight: bold;
         color: #680606;
         margin: 0;
         padding: 0;
      }

      td.mainbar h2 a {
         font-family: Arial;
         font-size: 16px;
         font-weight: bold;
         color: #680606;
         text-decoration: none;
         margin: 0;
         padding: 0;
      }

      td.mainbar img.hr {
         margin: 0;
         padding: 0 0 10px 0;
      }

      td.mainbar p {
         font-family: Arial;
         font-size: 13px;
         font-weight: normal;
         color: #333333;
         margin: 0 0 14px 0;
         padding: 0;
      }

      td.mainbar p a {
         font-family: Arial;
         font-size: 13px;
         font-weight: normal;
         color: #680606;
      }

      td.mainbar p.more a {
         font-family: Arial;
         font-size: 13px;
         font-weight: normal;
         color: #680606;
         text-decoration: none;
      }

      td.mainbar ul {
         font-family: Arial;
         font-size: 13px;
         font-weight: normal;
         color: #333333;
         margin: 0 0 14px 24px;
         padding: 0;
      }

      td.mainbar ul li a {
         font-family: Arial;
         font-size: 13px;
         font-weight: normal;
         color: #680606;
      }

      td.footer {
         padding: 0 20px 0 20px;
         background-image: url('mail/footer-bg.gif');
         background-repeat: no-repeat;
         background-position: top center;
         background-color: #333333;
         height: 61px;
         vertical-align: middle;
      }

      td.footer p {
         font-family: Arial;
         font-size: 11px;
         font-weight: normal;
         color: #ffffff;
         line-height: 16px;
         margin: 0;
         padding: 0;
      }
   </style>
</head>
<body>

<table width='100%' border='0' cellspacing='0' cellpadding='0' class='bg1'>
   <tr>
      <td align='center'>
         
         <table width='600' border='0' cellspacing='0' cellpadding='0' class='bg2'>
            <tr>
               <td valign='top' class='body'>
                  <table width='100%' border='0' cellspacing='0' cellpadding='0'>
                     <tr>
                        <td valign='top' width='600' class='sidebar' align='left'>
<br/><br/>
                           <p><strong>$today</strong></p>
<p>$message3</p>

<p>Regards,<br>
DC Repairs Team<br>
www.dcrepairs.co.uk</p>
                        </td>                    
                     </tr>
                  </table>         
            <tr>
               <td valign='middle' align='left' class='footer' height='61'>
                  <p>DCRepairs, part of the DCRepairs Group © 2009 - 2010.<br />
                  <p>07951 520 538 - [email protected]</p>
               </td>
            </tr>
         </table>
         
      </td>
   </tr>
</table>

</body>
</html>
";

////HEADERS
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: DCRepairs <[email protected]>' . "\r\n";

////SEND



mail($to, $subject, $message, $headers);


mysql_query("INSERT INTO emails (`id`, `to`, `from`, `subject`, `date`) 
VALUES ('', '$to', 'Mass Email', '$subject', '$today')");

die ("Sent.<meta http-equiv='REFRESH' content='1;url=mail2.php'>");

}}

?>
<p>
<center>
<form name=email method=post action=>
<table width=90% border=0>
<tr>
<td bgcolor='#F0F0F0'>
Email Address
</td>
<td bgcolor='#F0F0F0'>
<?php
$query2  = "SELECT * FROM mailinglist";
$result2 = mysql_query($query2);

while($row2 = mysql_fetch_array($result2, MYSQL_ASSOC))
{

echo " $row2[email]"; 
}
?>
</td>
</tr>
<tr>
<td bgcolor='#F0F0F0'>
Subject
</td>
<td bgcolor='#F0F0F0'>
<input type=text name=subject class=inputDetails size=35>
</td>
</tr>
</table>
<table width='90%' border='0'>
<tr>
<td bgcolor='#F0F0F0'>
<center>Message Body
<br>
<textarea name='desc' cols='80' rows='10'></textarea>
<br>
<center>
<input type=submit name=submit value=Send class=button>
</td>
</tr>
</table>
</center>
</p>

<div id="footer"><span class="links">
<a href="data.php">data protection </a> | <a href="terms.php"> terms & conditions </a> | <a href="contact.php"> contact us</a>            
          
          
          
          
          
          
          
          
          
<strong>© 2009 - 2010 DC Repairs Group</strong>
</span>
</div>

<div id="webmailFooter">
	<a href="https://mail.dcrepairs.co.uk/">Webmail</a>
</div>

<div id="logos">
	<p><a href="http://validator.w3.org/check?uri=referer" target="_blank"><img
	src="http://www.w3.org/Icons/valid-xhtml10"
	alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></p>

	<p><a href="http://www.php.net/" target="_blank"><img
	src="templates/colyer1.1/images/php5-powered.png"
	alt="PHP5 Powered" height="15" width="80" /></a>

	<a href="http://www.mysql.com/" target="_blank"><img
	src="templates/colyer1.1/images/mysql-powered.png"
	alt="MySQL Powered" height="15" width="80" /></a></p>
</div>

</div>

</body>

</html>
<?php
}
?>

Link to comment
https://forums.phpfreaks.com/topic/194601-mass-email-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.