The PHP Manual clearly states that to send an HTML email, the header Content-type: text/html;
.
And, if you want to send HTML it is recommended to build an HTML document with at least the basic elements of it (labels <html>, <head>, <body>
... both opening and closing.
This example code is the same as in the Manual. If you have problems with the accents, you can indicate: charset=UTF-8
instead of: charset=iso-8859-1
.
<?php
// Varios destinatarios
$para = '[email protected]' . ', '; // atención a la coma
$para .= '[email protected]';
// título
$título = 'Recordatorio de cumpleaños para Agosto';
// mensaje
$mensaje = '
<html>
<head>
<title>Recordatorio de cumpleaños para Agosto</title>
</head>
<body>
<p>¡Estos son los cumpleaños para Agosto!</p>
<table>
<tr>
<th>Quien</th><th>Día</th><th>Mes</th><th>Año</th>
</tr>
<tr>
<td>Joe</td><td>3</td><td>Agosto</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17</td><td>Agosto</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
// Para enviar un correo HTML, debe establecerse la cabecera Content-type
$cabeceras = 'MIME-Version: 1.0' . "\r\n";
$cabeceras .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Cabeceras adicionales
$cabeceras .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
$cabeceras .= 'From: Recordatorio <[email protected]>' . "\r\n";
$cabeceras .= 'Cc: [email protected]' . "\r\n";
$cabeceras .= 'Bcc: [email protected]' . "\r\n";
// Enviarlo
mail($para, $título, $mensaje, $cabeceras);
?>