Jump to content

Recommended Posts

I have a script that adds things to the database, then is suppose to send an email, with everything in the message, to one person.

I can get the script to send, but it only shows one item, and it's suppose to show every one of the picks.

 

Here is my script.

<?php
if(isset($_POST['submit'])){
		  include("connect.php");
		  			
if (!empty($_POST['description'])) {
  			foreach($_POST['description'] as $row=>$Act) {
      $description = mysql_real_escape_string($Act);      
      $game = $_POST['posted_y'][$row]."-".$_POST['posted_m'][$row]."-".$_POST['posted_d'][$row];
      $game_time = mysql_real_escape_string($_POST['game_time'][$row]);
  $game_time1 = mysql_real_escape_string($_POST['game_time1'][$row]);
      $away_team = mysql_real_escape_string($_POST['away'][$row]);
      $home_team = mysql_real_escape_string($_POST['home'][$row]);
      $premiere = mysql_real_escape_string($_POST['premiere'][$row]);
  $prediction = mysql_real_escape_string($_POST['prediction'][$row]);
  $week = mysql_real_escape_string($_POST['week'][$row]);
  $posted_date = $_POST['posted_year']."-".$_POST['posted_month']."-".$_POST['posted_day'];
      $sport = mysql_real_escape_string($_POST['sport']);
      if (!empty($description)) {
         $sql = "INSERT INTO picks(sport, posted, game, game_time, game_time1, description, away, home, prediction, premiere, week) VALUES(
                        '$sport',
                        '$posted_date',
                        '$game',
                        '$game_time',
					'$game_time1',
                        '$description',
                        '$away_team',
                        '$home_team',
					'$prediction',
                        '$premiere',
					'$week');";
                        mysql_query($sql)
                        or die("Sorry, there was a problem adding picks<br /> ".mysql_error());


						$sql1 = "SELECT * FROM $sport WHERE id = '$home_team'";
							$q1= mysql_query($sql1); 
							while($a1= mysql_fetch_assoc($q1)){									
								$home_team1 = $a1['team'];								
							}
							$sql2 = "SELECT * FROM $sport WHERE id = '$away_team'";
							$q2= mysql_query($sql2); 
							while($a2= mysql_fetch_assoc($q2)){									
								$away_team1 = $a2['team'];
							}
				}
			}

$message = "
<html>
<style type='text/css'>
<!--
body,td,th {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
.main {
border: thin solid #000;
}
.header {
color: #fff;
font-weight: bold;
}
-->
</style>
<body>
<table width='600' border='0' align='center' cellpadding='6' cellspacing='0' class='main'>
  <tr>
    <td align='center' valign='top' bgcolor='#333333' class='header'><h2>10 FREE FOOTBALL PICKS UPDATE</h2></td>
  </tr>
  <tr>
    <td valign='top' align='left'><table width='100%' border='0' cellspacing='0' cellpadding='6'>
      <tr>
        <td colspan='4' bgcolor='#d6d5d5'>The following 'picks' information has been uploaded.</td>
      </tr>
      <tr>
        <td bgcolor='#d6d5d5'>

<table width='100%' border='0' cellspacing='0' cellpadding='0'>
            <tr>
              <td><strong>Date: </strong>$today</td>
              </tr>
            <tr>
              <td>Game: $game
              </tr>
		  <tr>
		<td>$away_team1 vs $home_team1</td>
		</tr>
		<tr>
	<td>$game_time</td>
	</tr>
	<tr>
	<td>$description<br />$prediction</td>
	</tr>
        </table>
	</td>
      </tr>
      <tr>
        <td colspan='4' bgcolor='#d6d5d5'> </td>
      </tr>
    </table></td>
  </tr>

</table>
</body>
</html>";


$to = "Vegas D Sports <tpatterson@cheezyfries.net>";
//$to = "Vegas D Sports <notify@vegasdsports.com>";
$today = date("F j, Y", strtotime($posted_date));
$today1 = $posted_date;
$subject = "10FreeFootballPicks.com Pick Updates For ".$today."";
$name = "10FreeFootballPicks.com";
$from = "website@10FreeFootballPicks.com";
$headers = "From: ". $name . " <" . $from . ">\r\n";
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"";
$headers .= "Content-Transfer-Encoding: 7bit";
//$headers .= 'Cc: dgriffin@cpcsllc.com' . "\r\n";
//$headers .= 'Bcc: tpatterson@cheezyfries.net' . "\r\n";
// now lets send the email.
}
mail($to, $subject, $message, $headers);



echo "Picks for '".date("F j, Y", strtotime($posted_date))."' has been uploaded<br />";
echo "<a href='$back'>Go back to picks page</a>";

}
?>

Can anybody see why it I have more than 2 messages, it only send the last one?

 

Thanks in advance

 

Link to comment
https://forums.phpfreaks.com/topic/175498-solved-foreach/
Share on other sites

This is what I did, and now, it sends 10 different emails, all with different picks.

I'd like this to send 1 email, with all the picks in the 1 emails

              <?php
		  if(isset($_POST['submit'])){
		  include("connect.php");
		  			
if (!empty($_POST['description'])) {
  			foreach($_POST['description'] as $row=>$Act) {
      $description = mysql_real_escape_string($Act);      
      $game = $_POST['posted_y'][$row]."-".$_POST['posted_m'][$row]."-".$_POST['posted_d'][$row];
      $game_time = mysql_real_escape_string($_POST['game_time'][$row]);
  $game_time1 = mysql_real_escape_string($_POST['game_time1'][$row]);
      $away_team = mysql_real_escape_string($_POST['away'][$row]);
      $home_team = mysql_real_escape_string($_POST['home'][$row]);
      $premiere = mysql_real_escape_string($_POST['premiere'][$row]);
  $prediction = mysql_real_escape_string($_POST['prediction'][$row]);
  $week = mysql_real_escape_string($_POST['week'][$row]);
  $posted_date = $_POST['posted_year']."-".$_POST['posted_month']."-".$_POST['posted_day'];
      $sport = mysql_real_escape_string($_POST['sport']);
      if (!empty($description)) {
         $sql = "INSERT INTO picks(sport, posted, game, game_time, game_time1, description, away, home, prediction, premiere, week) VALUES(
                        '$sport',
                        '$posted_date',
                        '$game',
                        '$game_time',
					'$game_time1',
                        '$description',
                        '$away_team',
                        '$home_team',
					'$prediction',
                        '$premiere',
					'$week');";
                        mysql_query($sql)
                        or die("Sorry, there was a problem adding picks<br /> ".mysql_error());


						$sql1 = "SELECT * FROM $sport WHERE id = '$home_team'";
							$q1= mysql_query($sql1); 
							while($a1= mysql_fetch_assoc($q1)){	

								$home_team1 = $a1['team'];

							}
							$sql2 = "SELECT * FROM $sport WHERE id = '$away_team'";
							$q2= mysql_query($sql2); 
							while($a2= mysql_fetch_assoc($q2)){	

								$away_team1 = $a2['team'];

							}	
//$to = "Vegas D Sports <tpatterson@cheezyfries.net>";
$to = "Vegas D Sports <notify@vegasdsports.com>";

$today = date("F j, Y", strtotime($posted_date));
$today1 = $posted_date;
$subject = "10FreeFootballPicks.com Pick Updates For ".$today."";

$message = "
<html>
<style type='text/css'>
<!--
body,td,th {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
.main {
border: thin solid #000;
}
.header {
color: #fff;
font-weight: bold;
}
-->
</style>
<body>
<table width='600' border='0' align='center' cellpadding='6' cellspacing='0' class='main'>
  <tr>
    <td align='center' valign='top' bgcolor='#333333' class='header'><h2>10 FREE FOOTBALL PICKS UPDATE</h2></td>
  </tr>
  <tr>
    <td valign='top' align='left'><table width='100%' border='0' cellspacing='0' cellpadding='6'>
      <tr>
        <td colspan='4' bgcolor='#d6d5d5'>The following 'picks' information has been uploaded.</td>
      </tr>
      <tr>
        <td bgcolor='#d6d5d5'>

<table width='100%' border='0' cellspacing='0' cellpadding='0'>
            <tr>
              <td><strong>Date: </strong>$today</td>
              </tr>
            <tr>
              <td>Game: $game
              </tr>
		  <tr>
		<td>$away_team1 vs $home_team1</td>
		</tr>
		<tr>
	<td>$game_time</td>
	</tr>
	<tr>
	<td>$description<br />$prediction</td>
	</tr>
        </table>
	</td>
      </tr>
      <tr>
        <td colspan='4' bgcolor='#d6d5d5'> </td>
      </tr>
    </table></td>
  </tr>

</table>
</body>
</html>
";


$name = "10FreeFootballPicks.com";
$from = "website@10FreeFootballPicks.com";
$headers = "From: ". $name . " <" . $from . ">\r\n";
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"";
$headers .= "Content-Transfer-Encoding: 7bit";
$headers .= 'Cc: dgriffin@cpcsllc.com' . "\r\n";
//$headers .= 'Bcc: tpatterson@cheezyfries.net' . "\r\n";
// now lets send the email.

mail($to, $subject, $message, $headers);
}
}
}

echo "Picks for '".date("F j, Y", strtotime($posted_date))."' has been uploaded<br />";
echo "<a href='$back'>Go back to picks page</a>";

}
?>

Link to comment
https://forums.phpfreaks.com/topic/175498-solved-foreach/#findComment-924768
Share on other sites

ok, it's outside the foreach loop, now I'm back to square 1.

Sends 1 email, with only the last pick in the body

              <?php
		  if(isset($_POST['submit'])){
		  include("connect.php");
		  			
if (!empty($_POST['description'])) {
  			foreach($_POST['description'] as $row=>$Act) {
      $description = mysql_real_escape_string($Act);      
      $game = $_POST['posted_y'][$row]."-".$_POST['posted_m'][$row]."-".$_POST['posted_d'][$row];
      $game_time = mysql_real_escape_string($_POST['game_time'][$row]);
  $game_time1 = mysql_real_escape_string($_POST['game_time1'][$row]);
      $away_team = mysql_real_escape_string($_POST['away'][$row]);
      $home_team = mysql_real_escape_string($_POST['home'][$row]);
      $premiere = mysql_real_escape_string($_POST['premiere'][$row]);
  $prediction = mysql_real_escape_string($_POST['prediction'][$row]);
  $week = mysql_real_escape_string($_POST['week'][$row]);
  $posted_date = $_POST['posted_year']."-".$_POST['posted_month']."-".$_POST['posted_day'];
      $sport = mysql_real_escape_string($_POST['sport']);
      if (!empty($description)) {
         $sql = "INSERT INTO picks(sport, posted, game, game_time, game_time1, description, away, home, prediction, premiere, week) VALUES(
                        '$sport',
                        '$posted_date',
                        '$game',
                        '$game_time',
					'$game_time1',
                        '$description',
                        '$away_team',
                        '$home_team',
					'$prediction',
                        '$premiere',
					'$week');";
                        mysql_query($sql)
                        or die("Sorry, there was a problem adding picks<br /> ".mysql_error());


						$sql1 = "SELECT * FROM $sport WHERE id = '$home_team'";
							$q1= mysql_query($sql1); 
							while($a1= mysql_fetch_assoc($q1)){	

								$home_team1 = $a1['team'];

							}
							$sql2 = "SELECT * FROM $sport WHERE id = '$away_team'";
							$q2= mysql_query($sql2); 
							while($a2= mysql_fetch_assoc($q2)){	

								$away_team1 = $a2['team'];

							}	
$to = "Vegas D Sports <tpatterson@cheezyfries.net>";
//$to = "Vegas D Sports <notify@vegasdsports.com>";

$today = date("F j, Y", strtotime($posted_date));
$today1 = $posted_date;
$subject = "10FreeFootballPicks.com Pick Updates For ".$today."";

$message = "
<html>
<style type='text/css'>
<!--
body,td,th {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
.main {
border: thin solid #000;
}
.header {
color: #fff;
font-weight: bold;
}
-->
</style>
<body>
<table width='600' border='0' align='center' cellpadding='6' cellspacing='0' class='main'>
  <tr>
    <td align='center' valign='top' bgcolor='#333333' class='header'><h2>10 FREE FOOTBALL PICKS UPDATE</h2></td>
  </tr>
  <tr>
    <td valign='top' align='left'><table width='100%' border='0' cellspacing='0' cellpadding='6'>
      <tr>
        <td colspan='4' bgcolor='#d6d5d5'>The following 'picks' information has been uploaded.</td>
      </tr>
      <tr>
        <td bgcolor='#d6d5d5'>

<table width='100%' border='0' cellspacing='0' cellpadding='0'>
            <tr>
              <td><strong>Date: </strong>$today</td>
              </tr>
            <tr>
              <td>Game: $game
              </tr>
		  <tr>
		<td>$away_team1 vs $home_team1</td>
		</tr>
		<tr>
	<td>$game_time</td>
	</tr>
	<tr>
	<td>$description<br />$prediction</td>
	</tr>
        </table>
	</td>
      </tr>
      <tr>
        <td colspan='4' bgcolor='#d6d5d5'> </td>
      </tr>
    </table></td>
  </tr>

</table>
</body>
</html>
";


$name = "10FreeFootballPicks.com";
$from = "website@10FreeFootballPicks.com";
$headers = "From: ". $name . " <" . $from . ">\r\n";
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"";
$headers .= "Content-Transfer-Encoding: 7bit";
//$headers .= 'Cc: dgriffin@cpcsllc.com' . "\r\n";
//$headers .= 'Bcc: tpatterson@cheezyfries.net' . "\r\n";
// now lets send the email.


}
}
mail($to, $subject, $message, $headers);
}

echo "Picks for '".date("F j, Y", strtotime($posted_date))."' has been uploaded<br />";
echo "<a href='$back'>Go back to picks page</a>";

}
?>

Link to comment
https://forums.phpfreaks.com/topic/175498-solved-foreach/#findComment-924775
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.