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 <myemail@myemail.com>");

   $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 <myemail@myemail.com>")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
Share on other sites

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

 

$okemail = mail($email, $subject,$message, "From:League Admin <myemail@myemail.com>")or die("Could not send mail");

 

Should be:

 

mail($email, $subject, $message, "From:League Admin <myemail@myemail.com>")or die("Could not send mail");

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.