Welcome to Dream.In.Code
Click Here
Getting PHP Help is Easy!

Join 117,572 PHP Programmers for FREE! Ask your question and get quick answers from experts. There are 1,981 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Sending Mass Emails

 
Reply to this topicStart new topic

Sending Mass Emails, trying to send mass emails according to email address in database

Ladydice
post 21 Jul, 2008 - 02:19 AM
Post #1


New D.I.C Head

*
Joined: 25 Jun, 2008
Posts: 18


My Contributions


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... biggrin.gif
CODE


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 Jul, 2008 - 02:22 AM
User is offlineProfile CardPM

Go to the top of the page


mocker
post 21 Jul, 2008 - 02:56 PM
Post #2


D.I.C Head

**
Joined: 14 Oct, 2007
Posts: 219



Thanked 11 times
My Contributions


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
User is offlineProfile CardPM

Go to the top of the page

Ladydice
post 28 Jul, 2008 - 08:13 PM
Post #3


New D.I.C Head

*
Joined: 25 Jun, 2008
Posts: 18


My Contributions


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

CODE


$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.. smile.gif
User is offlineProfile CardPM

Go to the top of the page

JBrace1990
post 28 Jul, 2008 - 08:34 PM
Post #4


D.I.C Regular

Group Icon
Joined: 9 Mar, 2008
Posts: 458



Thanked 20 times

Dream Kudos: 350
My Contributions


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


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

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

Go to the top of the page

Ladydice
post 28 Jul, 2008 - 11:02 PM
Post #5


New D.I.C Head

*
Joined: 25 Jun, 2008
Posts: 18


My Contributions


QUOTE(JBrace1990 @ 28 Jul, 2008 - 08:34 PM) *

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


that should throw errors itself... there's no semicolon at the end of $to...
php
$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.... icon_up.gif biggrin.gif thnk you so very much
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/7/08 08:40PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month