Foros del Web » Programando para Internet » PHP »

enviar noticias por e-mail

Estas en el tema de enviar noticias por e-mail en el foro de PHP en Foros del Web. Hola, en esta oportunidad estoy en el intento de enviar un resumen con las últimas noticias de un sitio por e-mail; no un newsletter sino ...
  #1 (permalink)  
Antiguo 31/07/2008, 00:22
 
Fecha de Ingreso: agosto-2004
Mensajes: 113
Antigüedad: 19 años, 8 meses
Puntos: 0
enviar noticias por e-mail

Hola, en esta oportunidad estoy en el intento de enviar un resumen con las últimas noticias de un sitio por e-mail; no un newsletter sino que un visitante complete un formulario con un campo nombre y un campo e-mail y que a ese e-mail le llegue un resumen del sitio, casi casi como si fuera una recomendación.
Esta casi terminado, falta probarlo.
Uso este codigo para el select
Código PHP:
<?php include ("coneccion.php");?>
<? $rsblog 
mysql_query("SELECT id, titulo, txt_principal FROM notas WHERE seccion_nota = 'Blog'");
                          list(
$bid$btitulo$btxt_principal) = mysql_fetch_array($rsblog);
                          
$rslistab = @mysql_fetch_array($rsblog);
                          
$mostrar $btxt_principal;
$p_blogexplode("\n"$mostrar);
$rsjardines mysql_query("SELECT id, titulo, txt_principal FROM notas WHERE seccion_nota = 'Jardines'");
                          list(
$jid$jtitulo$jtxt_principal) = mysql_fetch_array($rsjardines);
                          
$rslistajar = @mysql_fetch_array($rsjardines);
                          
$mostrar $jtxt_principal;
$p_jardinesexplode("\n"$mostrar);?>
y un echo para mostrarlos
Código PHP:
<? echo "<table width='200' border='0' cellspacing='0' cellpadding='0'>
  <tr>
    <td> 
                          <h3>BLOG</h3><a href='nota.php?id=$bid'><h4>$btitulo</h4></a><img src='fotos/$bid_.jpg' border='0' class='ordenar_foto' width='120'/>$p_blog[0]</td>
  </tr>
</table>
<table width='500' border='0' cellspacing='0' cellpadding='0'>
  <tr>
    <td>
                          <h3>JARDINES</h3><a href='nota.php?id=$jid'><h4>$jtitulo</h4></a><img src='fotos/$jid_.jpg' border='0' class='ordenar_foto' width='120'/>$p_jardines[0]</td>
  </tr>
</table> "
;?>
esto funciona bien porque es un solo dato de cada llamada.
El problema me surge cuando quiero que se vean no 1 noticia por cada llamada sino más de una.
Entonces hice
Código PHP:
<?
$rsblog 
mysql_query("SELECT * FROM notas WHERE seccion_nota = 'Blog' ORDER BY id DESC LIMIT 5");
while(
$rslistab = @mysql_fetch_array($rsblog)) {
y el echo
Código PHP:
<? echo " <a href='nota.php?id=".$rslistab['id']."' target='_blank'>".$rslistab['titulo']."</a><? } ?>";?>
y cuando intento hacer esto último no muestra nada o muestra errores $end o de comillas, etc.
Se puede hacer esto último?
Gracias, Germán
  #2 (permalink)  
Antiguo 31/07/2008, 02:23
Avatar de desendoll  
Fecha de Ingreso: mayo-2008
Mensajes: 340
Antigüedad: 15 años, 11 meses
Puntos: 3
Respuesta: enviar noticias por e-mail

no entiendo que quieres que te haga exactamente esto: </a><? } ?> en el echo, pero si, si que te debe funcionar. "Cierras" el while? pon el código completo del bucle
__________________
Francesc Jimenez
  #3 (permalink)  
Antiguo 01/08/2008, 12:08
rqd
 
Fecha de Ingreso: julio-2008
Mensajes: 228
Antigüedad: 15 años, 9 meses
Puntos: 8
Respuesta: enviar noticias por e-mail

el problema parece ser al cerrar el while (como dice desendoll), en la última linea no es necesario poner <? } ?>, con solamente poner la llave } cierras el while, puesto que ya estas dentro de un segmento de código php
  #4 (permalink)  
Antiguo 02/08/2008, 02:22
 
Fecha de Ingreso: agosto-2004
Mensajes: 113
Antigüedad: 19 años, 8 meses
Puntos: 0
Respuesta: enviar noticias por e-mail

Hola, corregi lo que me marcaron y funciona, corregi ademas las variables en el echo y llega bien salvo que el while no funciona correctamente, o sea no muestra las ultimas 5 notas sino que solo muestra la ultima.
aca el codigo que solo imprime el ultimo resultado
Código PHP:
<?
$rsblog 
mysql_query("SELECT * FROM notas WHERE seccion_nota = 'Blog' ORDER BY id DESC LIMIT 5");
while(
$rslistab = @mysql_fetch_array($rsblog)) { 
echo 
"<tr>";?>
Código PHP:
<td width='300' align='left' valign='top'><h3>BLOG</h3>
<
table width='300' border='0' cellspacing='0' cellpadding='0'>
<
tr>
<
td width='300' align='left' valign='top'><a href='nota.php?id=".$rslistab['id']."' target='_blank' class='ir'>".$rslistab['titulo']."</a></td>"; } ?> 
gracias otra vez
  #5 (permalink)  
Antiguo 02/08/2008, 05:56
Avatar de DooBie  
Fecha de Ingreso: septiembre-2004
Mensajes: 1.101
Antigüedad: 19 años, 7 meses
Puntos: 71
Respuesta: enviar noticias por e-mail

Cita:
Iniciado por moquehua Ver Mensaje
Hola, corregi lo que me marcaron y funciona, corregi ademas las variables en el echo y llega bien salvo que el while no funciona correctamente, o sea no muestra las ultimas 5 notas sino que solo muestra la ultima.
aca el codigo que solo imprime el ultimo resultado
Código PHP:
<?
$rsblog 
mysql_query("SELECT * FROM notas WHERE seccion_nota = 'Blog' ORDER BY id DESC LIMIT 5");
while(
$rslistab = @mysql_fetch_array($rsblog)) { 
echo 
"<tr>";?>
Código PHP:
<td width='300' align='left' valign='top'><h3>BLOG</h3>
<
table width='300' border='0' cellspacing='0' cellpadding='0'>
<
tr>
<
td width='300' align='left' valign='top'><a href='nota.php?id=".$rslistab['id']."' target='_blank' class='ir'>".$rslistab['titulo']."</a></td>"; } ?> 
gracias otra vez
por que no pones el codigo completo del while?
  #6 (permalink)  
Antiguo 03/08/2008, 00:11
 
Fecha de Ingreso: agosto-2004
Mensajes: 113
Antigüedad: 19 años, 8 meses
Puntos: 0
Respuesta: enviar noticias por e-mail

agrego el código completo de recomendar.php donde el while solo imprime un resultado
Código PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Recomendar</title>
<style type="text/css">
<!--
body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
}
-->
</style>
<link href="estilos.css" rel="stylesheet" type="text/css">
<?php
include ("../includes/data.php");
@
$Nombre1 $_POST['Nombre1'];
@
$Nombre2 $_POST['Nombre2'];
@
$Email1 $_POST['Email1'];
@
$Email2 $_POST['Email2'];


$rsblog mysql_query("SELECT id, titulo, txt_principal FROM notas WHERE seccion_nota = 'Blog'");
                          list(
$bid$btitulo$btxt_principal) = mysql_fetch_array($rsblog);
                          
$rslistab = @mysql_fetch_array($rsblog);
                          
$sacar "$bid";
                          
$mostrar $btxt_principal;
$p_blogexplode("\n"$mostrar);
$rsjardines mysql_query("SELECT id, titulo, txt_principal FROM notas WHERE seccion_nota = 'Jardines'");
                          list(
$jid$jtitulo$jtxt_principal) = mysql_fetch_array($rsjardines);
                          
$rslistajar = @mysql_fetch_array($rsjardines);
                          
$mostrar $jtxt_principal;
$p_jardinesexplode("\n"$mostrar);

$rslblog mysql_query("SELECT * FROM notas WHERE seccion_nota = 'Blog' id != ".$sacar." ORDER BY id DESC LIMIT 5");
while(
$rslistablog = @mysql_fetch_array($rslblog)) { 
echo 
"<tr>";

$receptor $Email2;
//************************************************************************//
$header "From: $Nombre1 <$Email1>\n";
$header .= "To: ".$Email2."\n";
$header .= "X-Mailer: PHP4\n"//mailer
$header .= "MIME-Version: 1.0\n";
$header .= "Reply-to: ".$Email1."\n";
$header .= "Content-type: text/html; charset=iso-8859-1\n";
//************************************************************************//

$subject "Recomendación de " $Nombre1;

$cuerpo "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
<html><head>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<title>novedades por e-mail</title>
<style type='text/css'>
<!--
body {COLOR:#666666;FONT-FAMILY: helvetica;FONT-STYLE: normal;FONT-WEIGHT: normal;TEXT-DECORATION: none;}
.top{border: 0px solid #999999;border-bottom:none;background: #ffffff; MARGIN-TOP:4px; PADDING:2px;FONT-SIZE:11px;}
.bottom{border: 0px solid #999999;border-top:none;background: #ffffff; PADDING:2px;FONT-SIZE:11px;}
.ir {FONT-FAMILY:helvetica;font-size:10pt; margin:1px;font-weight:normal;TEXT-DECORATION: none;color:#fea941}
.ir:hover {TEXT-DECORATION: underline;}
h3 {font-size:8pt; margin:1px;    font-weight:normal;    }
h4{border:0px;text-align:left;width:96%;margin-left:4px;margin-top:0px;text-decoration:none;color:#fea941;}
.ordenar_foto{float:left;margin-right:4px;margin-left:1px;margin-top:4px;margin-bottom:4px;padding:1px;border:1px solid #cccccc;background-color:#FFFFFF;}
.borde{border-bottom:1px solid #e1e1e1; font-size:11px;padding-top:4px;padding-bottom:4px;margin-bottom:4px;margin-top:4px;}
.left{border-right:1px solid #e1e1e1;font-size:11px;border-top:10px solid #ffffff;background-color:#fafafa;padding-left:2px;}
.principal{background-color:#FFFF99;padding:5px;border-top:10px solid #ffffff;}
.promociones{padding-top:10px;padding-left:2px;}
hr{ width:95%; border: 1px solid #e1e1e1;}
.foto{margin-right:4px;margin-left:0px;margin-top:4px;margin-bottom:4px;padding:1px;border:1px solid #cccccc;background-color:#FFFFFF;}
center{margin-top:0px;margin-bottom:0px;}
-->
</style>
</head>

<body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
<table width='500' height='82' border='0' align='center' cellpadding='0' cellspacing='0'>
                                    <tr> 
                                        <td width='500' align='left' valign='top' class='texto'>Hola " 
                                          
$Nombre2 ",<br>" .$Nombre1" le env&iacutea una recomendaci&oacute;n 
                                          <br />
                                          Este mensaje se env&iacute;a a pedido 
                                          de " 
.$Nombre1", quien proporcion&oacute; 
                                          su direcci&oacute;n de correo electr&oacute;nico<br />
                                          Lamentamos cualquier molestia que pudiera 
                                          causar 
                                        </td>
                                    </tr>
                                  </table>
                                  <table width='500' border='0' cellspacing='0' cellpadding='0' align='center' class='top'>
  <tr>
    <td><img src='/estilo/images/encabezado_home.png' border='0'/></td>
  </tr>
  <tr>
    <td class='principal'><h3>BLOG</h3><a href='/blog/nota.php?id="
.$bid."' class='ir' target='_blank'>".$btitulo."</a><br>".$p_blog[0]."<br><a href='/blog/nota.php?id=".$bid."' class='ir' target='_blank'>leer más</a></td>
  </tr>
</table>
<table width='500' border='0' cellspacing='0' cellpadding='0' align='center' class='bottom'>
  <tr>
    <td width='190' align='left' valign='top'><table width='190' border='0' cellspacing='0' cellpadding='0' class='left'>
      <tr>
        <td><h3>JARDINES</h3><a href='/estilo/leer.php?id="
.$jid."' class='ir'>".$jtitulo."</a><br><img src='estilo/fotos/".$jid."_.jpg' border='0' class='ordenar_foto'/>".$p_jardines[0]."<br>          <a href='/estilo/leer.php?id=".$jid."' class='ir'>leer más</a></td>
      </tr>
    </table></td>
    <td width='300' align='left' valign='top' class='promociones'><h3>ÚLTIMAS NOTAS</h3>
      <table width='300' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td width='300' align='left' valign='top' class='borde'><a href='blog/nota.php?id="
.$rslistablog['id']."' target='_blank' class='ir'>".$rslistablog['titulo']."</a></td>
</tr></table>     </td>  </tr></table>
</body></html>"
;}
mail($receptor,$subject,$cuerpo,$header);
  
?>
</head>

<body>
<table width="350" height="220" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td align="left" valign="top">
<table width="350" height="220" border="0" cellpadding="0" cellspacing="0" bgcolor="#F0F0F0">
        <tr>
          <td align="center" valign="middle"><table width="287" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td align="center" valign="middle" class="gracias">Su recomendaci&oacute;n ha sido enviada con &eacute;xito. <br>
                    <br>
                  gracias<br>
                    <br>
                  <a href="javascript:window.close();" class="listado">cerrar 
                  ventana</a></td>
              </tr>
          </table></td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>
espero que alguien me de una mano porque no le encuentro la vuelta, gracias
  #7 (permalink)  
Antiguo 03/08/2008, 06:10
Avatar de DooBie  
Fecha de Ingreso: septiembre-2004
Mensajes: 1.101
Antigüedad: 19 años, 7 meses
Puntos: 71
Respuesta: enviar noticias por e-mail

Cita:
Iniciado por moquehua Ver Mensaje
agrego el código completo de recomendar.php donde el while solo imprime un resultado
Código PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Recomendar</title>
<style type="text/css">
<!--
body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
}
-->
</style>
<link href="estilos.css" rel="stylesheet" type="text/css">
<?php
include ("../includes/data.php");
@
$Nombre1 $_POST['Nombre1'];
@
$Nombre2 $_POST['Nombre2'];
@
$Email1 $_POST['Email1'];
@
$Email2 $_POST['Email2'];


$rsblog mysql_query("SELECT id, titulo, txt_principal FROM notas WHERE seccion_nota = 'Blog'");
                          list(
$bid$btitulo$btxt_principal) = mysql_fetch_array($rsblog);
                          
$rslistab = @mysql_fetch_array($rsblog);
                          
$sacar "$bid";
                          
$mostrar $btxt_principal;
$p_blogexplode("\n"$mostrar);
$rsjardines mysql_query("SELECT id, titulo, txt_principal FROM notas WHERE seccion_nota = 'Jardines'");
                          list(
$jid$jtitulo$jtxt_principal) = mysql_fetch_array($rsjardines);
                          
$rslistajar = @mysql_fetch_array($rsjardines);
                          
$mostrar $jtxt_principal;
$p_jardinesexplode("\n"$mostrar);

$rslblog mysql_query("SELECT * FROM notas WHERE seccion_nota = 'Blog' id != ".$sacar." ORDER BY id DESC LIMIT 5");
while(
$rslistablog = @mysql_fetch_array($rslblog)) { 
echo 
"<tr>";

$receptor $Email2;
//************************************************************************//
$header "From: $Nombre1 <$Email1>\n";
$header .= "To: ".$Email2."\n";
$header .= "X-Mailer: PHP4\n"//mailer
$header .= "MIME-Version: 1.0\n";
$header .= "Reply-to: ".$Email1."\n";
$header .= "Content-type: text/html; charset=iso-8859-1\n";
//************************************************************************//

$subject "Recomendación de " $Nombre1;

$cuerpo "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
<html><head>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<title>novedades por e-mail</title>
<style type='text/css'>
<!--
body {COLOR:#666666;FONT-FAMILY: helvetica;FONT-STYLE: normal;FONT-WEIGHT: normal;TEXT-DECORATION: none;}
.top{border: 0px solid #999999;border-bottom:none;background: #ffffff; MARGIN-TOP:4px; PADDING:2px;FONT-SIZE:11px;}
.bottom{border: 0px solid #999999;border-top:none;background: #ffffff; PADDING:2px;FONT-SIZE:11px;}
.ir {FONT-FAMILY:helvetica;font-size:10pt; margin:1px;font-weight:normal;TEXT-DECORATION: none;color:#fea941}
.ir:hover {TEXT-DECORATION: underline;}
h3 {font-size:8pt; margin:1px;    font-weight:normal;    }
h4{border:0px;text-align:left;width:96%;margin-left:4px;margin-top:0px;text-decoration:none;color:#fea941;}
.ordenar_foto{float:left;margin-right:4px;margin-left:1px;margin-top:4px;margin-bottom:4px;padding:1px;border:1px solid #cccccc;background-color:#FFFFFF;}
.borde{border-bottom:1px solid #e1e1e1; font-size:11px;padding-top:4px;padding-bottom:4px;margin-bottom:4px;margin-top:4px;}
.left{border-right:1px solid #e1e1e1;font-size:11px;border-top:10px solid #ffffff;background-color:#fafafa;padding-left:2px;}
.principal{background-color:#FFFF99;padding:5px;border-top:10px solid #ffffff;}
.promociones{padding-top:10px;padding-left:2px;}
hr{ width:95%; border: 1px solid #e1e1e1;}
.foto{margin-right:4px;margin-left:0px;margin-top:4px;margin-bottom:4px;padding:1px;border:1px solid #cccccc;background-color:#FFFFFF;}
center{margin-top:0px;margin-bottom:0px;}
-->
</style>
</head>

<body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
<table width='500' height='82' border='0' align='center' cellpadding='0' cellspacing='0'>
                                    <tr> 
                                        <td width='500' align='left' valign='top' class='texto'>Hola " 
                                          
$Nombre2 ",<br>" .$Nombre1" le env&iacutea una recomendaci&oacute;n 
                                          <br />
                                          Este mensaje se env&iacute;a a pedido 
                                          de " 
.$Nombre1", quien proporcion&oacute; 
                                          su direcci&oacute;n de correo electr&oacute;nico<br />
                                          Lamentamos cualquier molestia que pudiera 
                                          causar 
                                        </td>
                                    </tr>
                                  </table>
                                  <table width='500' border='0' cellspacing='0' cellpadding='0' align='center' class='top'>
  <tr>
    <td><img src='/estilo/images/encabezado_home.png' border='0'/></td>
  </tr>
  <tr>
    <td class='principal'><h3>BLOG</h3><a href='/blog/nota.php?id="
.$bid."' class='ir' target='_blank'>".$btitulo."</a><br>".$p_blog[0]."<br><a href='/blog/nota.php?id=".$bid."' class='ir' target='_blank'>leer más</a></td>
  </tr>
</table>
<table width='500' border='0' cellspacing='0' cellpadding='0' align='center' class='bottom'>
  <tr>
    <td width='190' align='left' valign='top'><table width='190' border='0' cellspacing='0' cellpadding='0' class='left'>
      <tr>
        <td><h3>JARDINES</h3><a href='/estilo/leer.php?id="
.$jid."' class='ir'>".$jtitulo."</a><br><img src='estilo/fotos/".$jid."_.jpg' border='0' class='ordenar_foto'/>".$p_jardines[0]."<br>          <a href='/estilo/leer.php?id=".$jid."' class='ir'>leer más</a></td>
      </tr>
    </table></td>
    <td width='300' align='left' valign='top' class='promociones'><h3>ÚLTIMAS NOTAS</h3>
      <table width='300' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td width='300' align='left' valign='top' class='borde'><a href='blog/nota.php?id="
.$rslistablog['id']."' target='_blank' class='ir'>".$rslistablog['titulo']."</a></td>
</tr></table>     </td>  </tr></table>
</body></html>"
;}
mail($receptor,$subject,$cuerpo,$header);
  
?>
</head>

<body>
<table width="350" height="220" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td align="left" valign="top">
<table width="350" height="220" border="0" cellpadding="0" cellspacing="0" bgcolor="#F0F0F0">
        <tr>
          <td align="center" valign="middle"><table width="287" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td align="center" valign="middle" class="gracias">Su recomendaci&oacute;n ha sido enviada con &eacute;xito. <br>
                    <br>
                  gracias<br>
                    <br>
                  <a href="javascript:window.close();" class="listado">cerrar 
                  ventana</a></td>
              </tr>
          </table></td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>
espero que alguien me de una mano porque no le encuentro la vuelta, gracias
deberias poner la linea donde envias el email dentro del while.

otra cosa, en las etiquetas <img> y <a> lo ideal es poner las rutas completas y no relativas.

saludos!
  #8 (permalink)  
Antiguo 03/08/2008, 16:38
 
Fecha de Ingreso: agosto-2004
Mensajes: 113
Antigüedad: 19 años, 8 meses
Puntos: 0
Respuesta: enviar noticias por e-mail

si cambio esta linea
Código PHP:
</body></html>";}
mail($receptor,$subject,$cuerpo,$header);
  ?> 
por esta
Código PHP:
</body></html>
mail($receptor,$subject,$cuerpo,$header)";}
  ?> 
el mail no se envia aunque diga que si.
las rutas del <a> y <img> las pongo asi porque todavia no hay sitio.
gracias
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:05.