Sending Mass Emails

trying to send mass emails according to email address in database

Page 1 of 1

4 Replies - 934 Views - Last Post: 28 July 2008 - 11:02 PM Rate Topic: -----

#1 Ladydice  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 25-June 08

Sending Mass Emails

Posted 21 July 2008 - 02:19 AM

can anyone help me...i wan to send mass emails to winners of a certain contest...i don't know how to go about doing it. i've done a simple email to 1 person but how do i email to more then 1...this is part of my codes...

when the users click on Yes button it will update the contestant's status and send an email to that winner, the person who created the contest and the administrator...how do i can about doing so....the codes below can only email to 1 person... :D

if(isset($_POST['Yes'])){
include('db.php');
$username =  $_REQUEST['FormUsername'];

mysql_query("UPDATE Contestants SET STATUS = 'winner' WHERE CON_TITLE = '$CON_TITLE' AND USER_NAME = '$username' "); 

$result= mysql_query("SELECT DISTINCT Contestants.USER_NAME, Contestants.JOINED_DATE, Contestants.CON_TITLE, Contest2.END_DATE, Contest2.START_DATE, Contest2.CAT_TITLE, Contest2.CON_DESC, Contest2.PRIZE_AMT 
FROM Contest2, Contestants 
WHERE Contestants.USER_NAME = '$username'
AND Contestants.CON_TITLE = '$CON_TITLE'");

$count=mysql_num_rows($result);
echo 'count = '.$count;
}
//else{
//echo 'No result was returned';
//}

if($count==1){
//
$rows=mysql_fetch_array($result);

//// keep password in $your_password
$your_username	= $rows['USER_NAME'];
$your_con_title   = $rows['CON_TITLE'];
$your_con_desc	= $rows['CON_DESC'];
$your_cat_title   = $rows['CAT_TITLE'];
$your_joined_date = $rows['JOINED_DATE'];
$your_end_date	= $rows['END_DATE'];
$your_start_date  = $rows['START_DATE'];
$your_prize_amt   = $rows['PRIZE_AMT'];

// ---------------- SEND MAIL FORM ---------------- 
// send e-mail to ...
$to="test@hotmail.com"; 
//
// Your subject 
$subject="THE WINNERS!"; 

// From 
$header="from: PayPerConest <test@gmail.com>"; 

// Your message 
$messages= "Hello $your_username\r\n";
$messages.= "You're the winner of $your_con_title \r\n";
$messages.="Contest Description: $your_con_desc \r\n";
$messages.="Contest Category: $your_cat_title\r\n";
$messages.="Contest Date: $your_joined_date\r\n";
$messages.="End Date: $your_end_date\r\n";
$messages.="Start Date: $your_start_date\r\n";
$messages.="Prize Amount: $your_prize_amt\r\n";

// send email 
$sentmail = mail($to,$subject,$messages,$header); 

}

// if your email succesfully sent 
if($sentmail){
echo "Your Contestants have been notified via email.";
}



This post has been edited by Ladydice: 21 July 2008 - 02:22 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Sending Mass Emails

#2 mocker  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 50
  • View blog
  • Posts: 466
  • Joined: 14-October 07

Re: Sending Mass Emails

Posted 21 July 2008 - 02:56 PM

This line only fetches one result from the sql query:
$rows=mysql_fetch_array($result);

Instead of just pulling one, put it in a loop..
while($rows=mysql_fetch_array($result)){

and then close the loop after it sends the email:
$sentmail = mail($to,$subject,$messages,$header);
}

This is assuming your query will pull multiple rows from the database when it needs to
Was This Post Helpful? 0
  • +
  • -

#3 Ladydice  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 25-June 08

Re: Sending Mass Emails

Posted 28 July 2008 - 08:13 PM

i'm sorry but i'm still having some problems. the thing is the email addresses are taken from database using 3 different SQL queries...

this was what i did


$result2=mysql_query("Select c.CON_TITLE,c.USER_NAME,m.F_NAME,m.L_NAME from Contestants c, Membership m WHERE 
c.USER_NAME = m.USER_NAME and 
c.CON_TITLE = '$CON_TITLE'");

echo "Contest Title: " .$CON_TITLE;

//start of form
//echo "<form name='form1' method='POST' action=''>";
echo "<table border = '1'>";
echo "<tr><th>First name</th>";
echo "<th>Last name</th>";
echo "<th>Username</th>";
echo "<th>Yes</th>";
echo "<th>No</th>";


while($row=mysql_fetch_array($result2)) {


echo "<tr><td>";
echo "<form name='form1' method='POST' action=''>";
echo $row['F_NAME'].'</td><td>';
echo $row['L_NAME'].'</td><td>'; 
echo $row['USER_NAME'].'</td><td>';


echo "<input type='Submit' name='Yes' value='Yes'></td><td>";
echo "<input type='Submit' name='No' value='No'></td>";
echo "<input type='hidden' name='FormUsername' value='".$row['USER_NAME']."'/>";

echo "</form>";//end of form
}

"</tr>";
echo "</table>";


$username =  $_REQUEST['FormUsername'];

mysql_query("UPDATE Contestants SET STATUS = 'winner' WHERE CON_TITLE = '$CON_TITLE' AND USER_NAME = '$username' "); 

$result= mysql_query("SELECT DISTINCT Contestants.USER_NAME, Contestants.JOINED_DATE, Contestants.CON_TITLE, Contest2.END_DATE, Contest2.START_DATE, Contest2.CAT_TITLE, Contest2.CON_DESC, Contest2.PRIZE_AMT, Membership.USER_NAME, Membership.EMAIL 
FROM Contest2, Contestants, Membership 
WHERE Contestants.USER_NAME = '$username'
AND Contestants.USER_NAME = Membership.USER_NAME
AND Contestants.CON_TITLE = '$CON_TITLE'");


if ($rows=mysql_fetch_array($result)){

//information to be emailed
$your_username	= $rows['USER_NAME'];
$your_con_title   = $rows['CON_TITLE'];
$your_con_desc	= $rows['CON_DESC'];
$your_cat_title   = $rows['CAT_TITLE'];
$your_joined_date = $rows['JOINED_DATE'];
$your_end_date	= $rows['END_DATE'];
$your_start_date  = $rows['START_DATE'];
$your_prize_amt   = $rows['PRIZE_AMT'];

//will not be shown in email
$email = $rows['EMAIL'].

//getting adver's email
$email2_stat = mysql_query("SELECT Membership.EMAIL, Contest2.USER_NAME, Contest2.CON_TITLE FROM Membership, Contest2 
WHERE Contest2.USER_NAME = Membership.USER_NAME
AND Contest2.USER_NAME = '$_COOKIE[ID_my_site]'"); 

while ($email_rows2 =mysql_fetch_array($email2_stat)){
$username2 = $email_rows2['USER_NAME'].'</td><td>';
$email2 = $email_rows2['EMAIL'].'</td><td>';
}

//getting admin's email
$email3_stat = mysql_query("SELECT EMAIL, USER_NAME, ACCESS_LEVEL FROM Membership 
WHERE ACCESS_LEVEL = 'admin'"); 

while ($email_rows3 =mysql_fetch_array($email3_stat)){
$username3 = $email_rows3['USER_NAME'].'</td><td>';
$email3 = $email_rows3['EMAIL'].'</td><td>';
}

// ---------------- SEND MAIL FORM ---------------- 

// send e-mail to ...

//$to="lala@hotmail.com";

$to = $email . ', '
$to.  = $email2 . ', '; // note the comma
$to .= $email3 . ', ';

// Your subject 
$subject="PPC Forget password!"; 
//
// From 
$header="From: ppc<ppc@gmail.com>"; 
//
//// Your message 
$messages= "Hello $your_username\r\n";
$messages.= "You're the winner of $your_con_title \r\n";
$messages.="Contest Description: $your_con_desc \r\n";
$messages.="Contest Category: $your_cat_title\r\n";
$messages.="Contest Date: $your_joined_date\r\n";
$messages.="End Date: $your_end_date\r\n";
$messages.="Start Date: $your_start_date\r\n";
$messages.="Prize Amount: $your_prize_amt\r\n";

// send email 
$sentmail = mail($to,$subject,$messages,$header); 



$email is the winner
$email2 is the advertiser
$email3 is the admin

i cant seem to get the $to to read the emails from my DB. it only works when i type out the email adds. Could u kindly explain why is tat so....thanks your help would be very appreciated.. :)
Was This Post Helpful? 0
  • +
  • -

#4 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 110
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: Sending Mass Emails

Posted 28 July 2008 - 08:34 PM

$to = $email . ', '
$to.  = $email2 . ', '; // note the comma
$to .= $email3 . ', ';


that should throw errors itself... there's no semicolon at the end of $to...
$email3 = $email_rows3['EMAIL'].'</td><td>';

the to contains the html elements, so that's probably throwing it off too...
Was This Post Helpful? 0
  • +
  • -

#5 Ladydice  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 25-June 08

Re: Sending Mass Emails

Posted 28 July 2008 - 11:02 PM

View PostJBrace1990, on 28 Jul, 2008 - 08:34 PM, said:

$to = $email . ', '
$to.  = $email2 . ', '; // note the comma
$to .= $email3 . ', ';


that should throw errors itself... there's no semicolon at the end of $to...
$email3 = $email_rows3['EMAIL'].'</td><td>';

the to contains the html elements, so that's probably throwing it off too...


HEY! thanks....its working now.... :^: :D thnk you so very much
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1