Ver Mensaje Individual
  #14 (permalink)  
Antiguo 28/08/2013, 09:43
SeRgIeTTe
 
Fecha de Ingreso: agosto-2011
Mensajes: 45
Antigüedad: 12 años, 9 meses
Puntos: 0
Respuesta: Enviar mail desde PHP si se cumple condición

Por supuesto que no, pateketrueke, os muestro todo el código que sera más simple:
Código PHP:
<?php require_once('Connections/alumnos.php'); ?>
<?php 
require_once('Connections/faltas.php'); ?>
<?php 
require_once('Connections/incidencias.php');?>
<?php 
require_once('Connections/retardos.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

mysql_select_db($database_alumnos$alumnos);
$query_Recordsetalumnos "SELECT * FROM alumnos";
$Recordsetalumnos mysql_query($query_Recordsetalumnos$alumnos) or die(mysql_error());
$row_Recordsetalumnos mysql_fetch_assoc($Recordsetalumnos);
$totalRows_Recordsetalumnos mysql_num_rows($Recordsetalumnos);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<script src="jquery-mobile/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="jquery-mobile/jquery.mobile-1.0.min.js" type="text/javascript"></script>
</head>

<body>
<div data-role="page" id="page">
<div data-role="header">
        <h1>Alumnos</h1><a href="javascript:history.back()">Atrás</a>
    </div>
    &nbsp;
<table width="95%" border="1" align="center">
  <tr align="center" valign="middle">
    <td><strong>Imagen</strong></td>
    <td><strong>Nombre y Apellidos</strong></td>
    <td><strong>Tlf. Casa</strong></td>
    <td><strong>Movil Padre</strong></td>
    <td><strong>Movil Madre</strong></td>
    <td><strong>E-mail</strong></td>
    <td><strong>Nº Faltas</strong></td>
    <td><strong>Nº Incidencias</strong></td>
    <td><strong>Nº Retardos</strong></td>
  </tr>
  <?php do { ?>
    <tr align="center" valign="middle">
      <td><a href="<?php echo $row_Recordsetalumnos['Nombreyapellidos']; ?>.php"><?php echo $row_Recordsetalumnos['Imagen']; ?></a></td>
      <td><a href="<?php echo $row_Recordsetalumnos['Nombreyapellidos']; ?>"><?php echo $row_Recordsetalumnos['Nombreyapellidos']; ?></a></td>
            <td><?php echo $row_Recordsetalumnos['Tlf. Casa']; ?></td>
      <td><?php echo $row_Recordsetalumnos['Movil Padre']; ?></td>
      <td><?php echo $row_Recordsetalumnos['Movil Madre']; ?></td>
      <td><?php echo $row_Recordsetalumnos['Email']; ?></td>
      <td><?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

mysql_select_db($database_faltas$faltas);
$query_Recordset2 "SELECT *  FROM `faltasasistencia`.`faltaasistencia`
            WHERE (`Nombreyapellidos` LIKE '%{$row_Recordsetalumnos['Nombreyapellidos']}%')"
;
$Recordset2 mysql_query($query_Recordset2$faltas) or die(mysql_error());
$row_Recordset2 mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 mysql_num_rows($Recordset2);
?>

<?php echo $totalRows_Recordset2 ?>

<?php $Emailpadres $_POST["Email"]; ?>
    <?php
    
if ($totalRows_Recordset2 3){
     
    echo 
$Name "No name"//senders name  
    
$email "[email protected]"//senders e-mail adress  
    
$recipient "$Emailpadres"//recipient  
    
$mail_body "Texto para el destinatario"//mail body  
    
$subject "Sujeto"//subject  
    
$header "De: "$Name " <" $email ">\r\n"//optional headerfields  
     
    
mail($recipient$subject$mail_body$header); //mail command :)  
}
    
?>
 
 

<?php
mysql_free_result
($Recordset2);
?>
</td>


<td>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
  
  
}
}

mysql_select_db($database_incidencias$incidencias);
$query_Recordsetincidencias "SELECT * FROM incidencias WHERE (`Autor` LIKE '%{$row_Recordsetalumnos['Nombreyapellidos']}%')";
$Recordsetincidencias mysql_query($query_Recordsetincidencias$incidencias) or die(mysql_error());
$row_Recordsetincidencias mysql_fetch_assoc($Recordsetincidencias);
$totalRows_Recordsetincidencias mysql_num_rows($Recordsetincidencias);
?>

<?php echo $totalRows_Recordsetincidencias ?>
</td>
<td>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

mysql_select_db($database_retardos$retardos);
$query_Recordsetretardos "SELECT * FROM retardo WHERE (`Nombreyapellidos` LIKE '%{$row_Recordsetalumnos['Nombreyapellidos']}%')";
$Recordsetretardos mysql_query($query_Recordsetretardos$retardos) or die(mysql_error());
$row_Recordsetretardos mysql_fetch_assoc($Recordsetretardos);
$totalRows_Recordsetretardos mysql_num_rows($Recordsetretardos);

mysql_free_result($Recordsetretardos);
?>

<?php echo $totalRows_Recordsetretardos ?> 


</td>


    </tr>
    <?php } while ($row_Recordsetalumnos mysql_fetch_assoc($Recordsetalumnos)); ?>
    
    
</table>
&nbsp;
</body>
</html>

<?php
mysql_free_result
($Recordsetalumnos);
?>
Lo que muestra es una tabla dinámica con todos los datos que tengo en MySQL. Lo que quiero es que cuando la columna nº de faltas llegue a más de 3, envie un e-mail automaticamente al e-mail que se muestra en la tabla dinamica. No sé si me he explicado.

Un saludo!