Tema: enviar mails
Ver Mensaje Individual
  #3 (permalink)  
Antiguo 24/02/2009, 10:39
JoanGarcia
 
Fecha de Ingreso: febrero-2009
Mensajes: 24
Antigüedad: 15 años, 2 meses
Puntos: 2
Respuesta: enviar mails

Este codigo lo utilzo para un sistema de Mailing con Fckedit y despues envio a direcciones de una BBDD en MYSQL

<?php
//----------------------------------------------------------------------------
//--------------CONECTAMOS A LA BASE DE DATOS---------------------------------
//----------------------------------------------------------------------------
require_once('_MYSQL/MYSQL.php'); //Incluimos la cadena de conexion
mysql_select_db($database_MYSQL, $MYSQL);
$query_BD_mails = "SELECT * FROM mailing WHERE envio=1";//Enviamos solo los marcados
$BD_mails = mysql_query($query_BD_mails, $MYSQL) or die(mysql_error());
$row_BD_mails = mysql_fetch_assoc($BD_mails);
//$totalRows_BD_mails = mysql_num_rows($row_BD_mails);
//----------------------------------------------------------------------------
//---------------FIN DE LA CONEXION CON LA BASE DE DATOS----------------------
//----------------------------------------------------------------------------


//--------------------------------------------------------------------------
//------------------RECOGEMOS LOS DATOS DEL EDITOR fckeditor
//--------------------------------------------------------------------------
$sValue = stripslashes( $_POST['FCKeditor1'] ) ;
//-------------------------------------------------------------------------------
//------------------FIN RECOGEMOS LOS DATOS DEL EDITOR---------------------------
//-------------------------------------------------------------------------------

//-------------------------------------------------------------------------------
//-----------------------------ENVIO MAIL CON LIBRERIAS MAIL--------
//-------------------------------------------------------------------------------

$from = '[email protected]';
$subject = 'Promocion Mailing';
$email = '[email protected]';

//MONTAMOS EL CUEPO DEL MAIL
$message = $sValue;

//INICIALIZAMOS EL CONTADOR
$contador=0;

//MONTAMOS LAS DIRECCIONES EN COPIA OCULTA
$DireccionesCCO = "Bcc: ";
$DireccionesCCO2 = "[email protected]";
$DireccionesCCO3 = "\r\n";


//---------------BUCLE DE MYSQL---------------------------------------------------
//----PARA EVITAR QUE NOS BANEEN COMO SPAM HAREMOS LOS ENVIOS CADA 50 DIRECCIONES
//--------------------------------------------------------------------------------
do {
if ($contador>50)
{

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: Promocion <[email protected]>\r\n";
$headers .= "Bcc: ".$DireccionesCCO2."\r\n";
$headers .= "Reply-To: <[email protected]>\r\n";
$headers .= "X-Mailer: PHP/";

mail ($email, $subject, $message, $headers);

$DireccionesCCO2 = "";
$contador=0;

}else{

$DireccionesCCO2 .= ",".$row_BD_mails['EMAIL'];
$contador++;
}


} while ($row_BD_mails = mysql_fetch_assoc($BD_mails));
//----------------------------------------------------------------------------
//---------------FIN DE BUCLE MYSQL-------------------------------------------


$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: Promocion <[email protected]>\r\n";
$headers .= "Bcc: ".$DireccionesCCO2."\r\n";
$headers .= "Reply-To: <[email protected]>\r\n";
$headers .= "X-Mailer: PHP/";

mail ($email, $subject, $message, $headers);


//-------------------------------------------------------------------------------
//--------------------FIN ENVIO MAIL CON LIBRERIAS MAIL------------
//-------------------------------------------------------------------------------
?>
<body>
<table width="800" border="5" align="center" cellpadding="5" cellspacing="5">
<tr>
<td><?php echo $message; ?></td>
<td><div class="Boton"><a href="index.html">Salir</a></div></td>

</tr>
</table>
</body>
</html>[/PHP]