Add styles to an email sent from php

0

I would like to know how I can add styles to the data sent from php, this is my code but it does not work, it appears as if it were string in the mail:

$mensaje = "
        <!DOCTYPE html>
        <html lang='en'>
        <head>
            <meta charset='UTF-8'>
            <title>Document</title>
        </head>
        <body>
            <p style='font-size: 20px;'>Punto de Partida: " . $punto_partida . "</p>
            <p>Destino: " . $destino . "</p>
            <p>Fecha de inicio: " . $fecha_inicio . "</p>
            <p>Hora de inicio: " . $hora_inicio . "</p>
            <p>Nombre: " . $nombre . "</p>
            <p>Teléfono: " . $telefono . "</p>
            <p>Correo: " . $correo . "</p>
        </body>
        </html>";

This is what appears in the email:

<!DOCTYPE html>
                    <html lang='en'>
                    <head>
                            <meta charset='UTF-8'>
                            <title>Document</title>
                    </head>
                    <body>
                            <p style='font-size: 20px;'>Punto de Partida: Ejemplo punto  partida</p>
                            <p>Destino: ejemplo destino</p>
                            <p>Fecha de inicio: 2018-11-15</p>
                            <p>Hora de inicio: 01:00</p>
                            <p>Nombre: Ejemplo</p>
                            <p>Teléfono: 46512231456</p>
                            <p>Correo: [email protected]</p>
                    </body>
                    </html>
    
asked by Moisés Aguilar 12.11.2018 в 19:22
source

2 answers

0

It worked for me adding the following line:

"Content-Type: text/html; charset=ISO-8859-1\r\n";

I put that line here:

$cabeceras = "From: [email protected]" . "\r\n" .
        "Reply-To: [email protected]" . "\r\n" .
        "X-Mailer: PHP/" . phpversion() . "\r\n" .
        "Content-Type: text/html; charset=ISO-8859-1\r\n";

The code would look like this:

<?php 

if (isset($_POST["valor"])) {
    $variable = $_POST["valor"];
    $variable = $_POST["valor"];
    $variable = $_POST["valor"];
    $variable = $_POST["valor"];
    $variable = $_POST["valor"];
    $variable = $_POST["valor"];
    $variable = $_POST["valor"];

    $para = "[email protected]";
    $titulo = "Titulo";
    $mensaje = "
        <!DOCTYPE html>
        <html lang='en'>
        <head>
            <meta charset='UTF-8'>
            <title>Document</title>
        </head>
        <body>
            <p style='font-size: 20px;'>Texto: " . $variable . "</p>
            <p>Texto: " . $variable . "</p>
            <p>Texto: " . $variable . "</p>
            <p>Texto: " . $variable . "</p>
            <p>Texto: " . $variable . "</p>
            <p>Texto: " . $variable . "</p>
            <p>Texto: " . $variable . "</p>
        </body>
        </html>";
    $cabeceras = "From: [email protected]" . "\r\n" .
        "Reply-To: [email protected]" . "\r\n" .
        "X-Mailer: PHP/" . phpversion() . "\r\n" .
        "Content-Type: text/html; charset=ISO-8859-1\r\n";

    mail($para, $titulo, $mensaje, $cabeceras);
}

? >

    
answered by 12.11.2018 в 19:46
-1

the way you have it is the same as how I do it and it has always worked for me, the only thing I see different in your implementation is the inclusion of the DOCTYPE try removing the DOCTYPE line to see. example:

    
answered by 12.11.2018 в 19:45