customize welcome email sent from php

1

Good morning,

I can not find a way to personalize a welcome message that is sent after registering on the web. I see that it does not pay attention to HTML tags either.

I'm using:

$destinatario = $mail;
$contenido = "<br>Bienvenido a la web</br>,

Necesitas validar el correo para poder utilizar todas las características de la web e iniciar sesión.";

mail($destinatario,"",$contenido);

The email is sent but in plain text and the accents do not take them, I get for example sesión. instead of session.

    
asked by JetLagFox 21.05.2017 в 23:34
source

1 answer

1

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);
?>
    
answered by 22.05.2017 / 01:40
source