Jump to content

emailing from database table


phlash2k1

Recommended Posts

I am trying to send emails to players from my mysql database according to which drop down selection is made. The first dropdown is to email all players in the database and the 2nd selection is emailing by teams. Any help will be greatly appriciated. I am fairly new to php mysql

 

Nothing happens. No errors. I just don't receive an email

 

here is the code:

 

<?php
include("dbconnection.php");
   if (!isset($_POST['submit'])):
?>

<html>
<head>
<title>Football League Email</title>
</head>

<body>

<form method="post" action="<?=$_SERVER['PHP_SELF']?>">
<table align="center" bgcolor="#D6DEE7" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<b><h2>MAILING LIST ADMIN</h2></b>


Send message to:
<select name="to" size="1" style="background-color: #F7F7F7">
<option selected value="all">All Players
<option value="notall">By Team
</select>

Team:
<select name="team" size="5">
<OPTION value="0003">Boudreaux
<OPTION value="0004">Brazil

</select>

Title or Subject: <input name="subject" type=text maxlength=100 size=40>
Message:
<textarea wrap name="message" rows=10 cols=45></textarea>
<input type=submit name="submit" value="SUBMIT">
</td>
</tr>
</table>
</form>
</body>
</html>

<?php else:

  $to = $_POST['to'];
  $subject = $_POST['subject'];
  $message = $_POST['message'];
  $team = $_POST['team'];

  if ("all" == $to) {
   $x = 1;
   $hold = 50; // quantity of emails sent before 3 sec delay
   $emails = mysql_query("SELECT email FROM players");
   while ($sendemail = mysql_fetch_array($emails)) {
   $email = $sendemail["email"];
   mail($email, $subject,$message, "From:League Admin <[email protected]>");

   $x++;
    if($x == $hold) { // When $x is equal to $hold, a 3 sec delay will occur avoiding php to timeout
    sleep(3);
    $x = 0;
    }
   } // end of while loop
  } else {
   $byteam = mysql_query("SELECT email FROM players WHERE teamid = '$team'");
   while ($countmail = mysql_fetch_array($byteam)) {
   $email = $countmail["email"];
   $okemail = mail($email, $subject,$message, "From:League Admin <[email protected]>")or die("Could not send mail");
   $x++;
    if($x == $hold) { // When $x is equal to $hold, a 3 sec delay will occur avoiding php to timeout
    sleep(3);
    $x = 0;
    }
   } // end of while loop
  }
?>
<html>
<head>
</head>
<body>
SUCCESS!
</body>
</html>
<?php endif; ?>

Link to comment
https://forums.phpfreaks.com/topic/40278-emailing-from-database-table/
Share on other sites

You never actually send the email, you just set a variable:

 

$okemail = mail($email, $subject,$message, "From:League Admin <[email protected]>")or die("Could not send mail");

 

Should be:

 

mail($email, $subject, $message, "From:League Admin <[email protected]>")or die("Could not send mail");

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.