Ver Mensaje Individual
  #21 (permalink)  
Antiguo 25/12/2014, 02:19
moginn
(Desactivado)
 
Fecha de Ingreso: enero-2013
Mensajes: 289
Antigüedad: 11 años, 4 meses
Puntos: 10
Respuesta: Enviar un correo con aspecto web

Cita:
Iniciado por miriamgomez Ver Mensaje
Hola:

entiendo la teoria, pero me falta el paso practico:

- Tengo la base de datos, un codigo con el que leo la tabla y extraigo los correos

- Tengo por otro lado el codigo que envia los correos


Pero, como conecto ambos y que el campo $row[1] pase a $headers .= 'Bcc: [email protected]' . "\r\n";

un saludo
Versión 1: Mandar los correos uno por uno

Código PHP:
 <?php
mysql_connect
("localhost""mysql_user""mysql_password") or
    die(
"Could not connect: " mysql_error());
mysql_select_db("mydb");

$result mysql_query("SELECT email FROM mytable");

while (
$row mysql_fetch_array($result)) {
      
$to  $row[0];

      
// subject
      
$subject 'Birthday Reminders for August';

      
// message
      
$message '
      <html>
      <head>
    <title>Birthday Reminders for August</title>
      </head>
      <body>
    <p>Here are the birthdays upcoming in August!</p>
    <table>
      <tr>
        <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
      </tr>
      <tr>
        <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
      </tr>
      <tr>
        <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
      </tr>
    </table>
      </body>
      </html>
      '
;

      
// To send HTML mail, the Content-type header must be set
      
$headers  'MIME-Version: 1.0' "\r\n";
      
$headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";

      
// Additional headers
      
$headers .= 'From: Birthday Reminder <[email protected]>' "\r\n";

      
// Mail it
      
mail($to$subject$message$headers);
}

mysql_free_result($result);
?>
Versión 2: mandar los correos de golpe
Código PHP:
 <?php
mysql_connect
("localhost""mysql_user""mysql_password") or
    die(
"Could not connect: " mysql_error());
mysql_select_db("mydb");

$result mysql_query("SELECT email FROM mytable");
$addresses[] = array();
while(
$row mysql_fetch_array($result))
{
    
$addresses[] = $row[0];
}
$to implode(", "$addresses);

// subject
$subject 'Birthday Reminders for August';

// message
$message '
<html>
<head>
  <title>Birthday Reminders for August</title>
</head>
<body>
  <p>Here are the birthdays upcoming in August!</p>
  <table>
    <tr>
      <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
    </tr>
    <tr>
      <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
    </tr>
    <tr>
      <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
    </tr>
  </table>
</body>
</html>
'
;

// To send HTML mail, the Content-type header must be set
$headers  'MIME-Version: 1.0' "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";

// Additional headers
$headers .= 'From: Birthday Reminder <[email protected]>' "\r\n";

// Mail it
mail($to$subject$message$headers);
}

mysql_free_result($result);
?>

Última edición por moginn; 25/12/2014 a las 02:50