runnerjp Posted September 6, 2008 Share Posted September 6, 2008 hey guys... ok put together this bulk emailer using loop i have been sugested but i just wounderd if this is best way / fastest way to go ?? <?php //this is a bulk emailer $sql = mysql_query("SELECT * FROM mail",$db); $num_rows = mysql_num_rows($sql); while ($row = mysql_fetch_array($sql)) { // takeing weight off the server CPU by waiting 10 seconds between each mailout. sleep(10); if (!mail($row["address"], $subject = "Newsletter", $message = "Hi there .. text goes here. ","From: [email protected]\n")) { echo "<FONT FACE=VERDANA, ARIAL SIZE=2 Color=Blue>E R R O R <FONT Color=Blue> : Mail has not been sent to " . $row["address"] . "</FONT><BR>\n"; } else { echo "<FONT FACE=VERDANA, ARIAL SIZE=2>" . $row["address"] . "</FONT><BR>\n"; } } mysql_close($db); ?> Link to comment https://forums.phpfreaks.com/topic/122998-bulk-emailer/ Share on other sites More sharing options...
runnerjp Posted September 6, 2008 Author Share Posted September 6, 2008 what have i done wrong here $sql = mysql_query("SELECT * FROM mail"); $num_rows = mysql_num_rows($sql); while ($row = mysql_fetch_array($sql)) { also i wrote out the script too look like below... is this correct?? cant test it as above script is wrong <?php session_start(); require_once '../settings.php'; checkLogin ('1 2'); $user= get_username($_SESSION['user_id']); //So here we get the variable submitted through the form to this page $subject1 = mysql_real_escape_string($_POST['subject']); $message1 = mysql_real_escape_string($_POST['message']); $timestamp = time(); $error = '0'; //If they are all blank we jsut say to compose a message if(!$subject AND !$message) { ?> <p><b>Please compose a message.</b> <?php } //Since this form was partially filled out we need to return an error message else { if (!$subject) { $error = 'You must enter a subject'; } if (!$message) { $error = 'You must enter a message'; } //If the variable error is not set to zero, we have a problem and should show the error message if($error != '0') { echo "<p>$error</p><br>"; } else { $pm_count = $pm_count + '1'; //Update Them mysql_query("UPDATE users SET pm_count='$pm_count' WHERE username='$reciever'"); $query = "SELECT * FROM users WHERE Username = '$reciever' LIMIT 1"; if ($result = mysql_query($query)){ if (mysql_num_rows($result)) { $array = mysql_fetch_assoc($result); $pemail = $array['Email']; $puser = $array['Username']; } // insert emailer //this is a bulk emailer $sql = mysql_query("SELECT Email FROM users"); $num_rows = mysql_num_rows($sql); while ($row = mysql_fetch_array($sql)) { if (!mail($row["Email"] //this is a bulk emailer $sql = mysql_query("SELECT * FROM mail"); $num_rows = mysql_num_rows($sql); while ($row = mysql_fetch_array($sql)) { if (!mail($row["Email"], $subject = $subject1, $message = $message1 ,"From: [email protected]\n")) { echo "<FONT FACE=VERDANA, ARIAL SIZE=2 Color=Blue>E R R O R <FONT Color=Blue> : Mail has not been sent to " . $row["address"] . "</FONT><BR>\n"; } else { echo "<FONT FACE=VERDANA, ARIAL SIZE=2>" . $row["address"] . "</FONT><BR>\n"; } },"From: [email protected]\n")) { echo "<FONT FACE=VERDANA, ARIAL SIZE=2 Color=Blue>E R R O R <FONT Color=Blue> : Mail has not been sent to " . $row["address"] . "</FONT><BR>\n"; } else { echo "<FONT FACE=VERDANA, ARIAL SIZE=2>" . $row["address"] . "</FONT><BR>\n"; } } else { //Here's the form for the input ?> </p> <form name="send" method="post" action="index.php?page=compose"> <table width="80%"> <tr> <td width="150" align="left" valign="top"><p>Username</p></td> <td width="" align="left" valign="top"> </td> </tr> <tr> <td width="150" align="left" valign="top"><p>Subject</p></td> <td width="" align="left" valign="top"><input class="inputinbox" name="subject" type="text" id="subject" value="<?php echo "$subject"; ?>"></td> </tr> <tr> <td width="150" align="left" valign="top"><p>Message Body</p></td> <td width="" align="left" valign="top"><textarea class="inputinbox" name="message" type="text" id="message" value="" cols="50" rows="10"></textarea></td> </tr> <tr> <td colspan="2"><input type="submit" name="Submit" class="submit-btn" value=""></td> </tr> </table> </center> </form> <?php } } ?> Link to comment https://forums.phpfreaks.com/topic/122998-bulk-emailer/#findComment-635157 Share on other sites More sharing options...
The Little Guy Posted September 6, 2008 Share Posted September 6, 2008 For sending large Emails, it is recommended that you use http://pear.php.net/package/Mail Are you getting an error message? Link to comment https://forums.phpfreaks.com/topic/122998-bulk-emailer/#findComment-635199 Share on other sites More sharing options...
runnerjp Posted September 6, 2008 Author Share Posted September 6, 2008 hey ..still learning php and not used pear ever so wanna sort it out with php so i can learn abit yes i get an error message unexpected ; for $sql = mysql_query("SELECT Email FROM users"); <?php if (!mail($row["Email"], //this is a bulk emailer $sql = mysql_query("SELECT Email FROM users"); $num_rows = mysql_num_rows($sql); while ($row = mysql_fetch_array($sql)) { if (!mail($row["Email"], $subject = $subject1, $message = $message1 ,"From: [email protected]\n")) { echo "<FONT FACE=VERDANA, ARIAL SIZE=2 Color=Blue>E R R O R <FONT Color=Blue> : Mail has not been sent to " . $row["address"] . "</FONT><BR>\n"; } else { echo "<FONT FACE=VERDANA, ARIAL SIZE=2>" . $row["address"] . "</FONT><BR>\n"; } },"From: [email protected]\n")) { echo "<FONT FACE=VERDANA, ARIAL SIZE=2 Color=Blue>E R R O R <FONT Color=Blue> : Mail has not been sent to " . $row["address"] . "</FONT><BR>\n"; } else { echo "<FONT FACE=VERDANA, ARIAL SIZE=2>" . $row["address"] . "</FONT><BR>\n"; } }?> Link to comment https://forums.phpfreaks.com/topic/122998-bulk-emailer/#findComment-635209 Share on other sites More sharing options...
The Little Guy Posted September 6, 2008 Share Posted September 6, 2008 Remove this line: if (!mail($row["Email"], Link to comment https://forums.phpfreaks.com/topic/122998-bulk-emailer/#findComment-635211 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.