Customize the arrival of mail with CSS through PHPMailer

3

Hello, how I have a question:

I am sending a table of 5 columns and 4 rows. It is very simple. I'm doing it within phpmailer and I enclose it with double quotes and the content in quotes simpres.

What I see is that when I send the email, when I receive it, it is completely out of square. The table does not respect the CSS . I try to integrate it with Bootstrap but it just seems to ignore it.

Before sending, it is displayed as follows:

And when the email arrives:

.

This is my code:

<!DOCTYPE html>
<html lang="es">
    <head>
        <meta charset="utf-8">
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1 user-scalable=no">
        <title>ENVIO DE DATOS</title>
        <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.css">
        <link rel="stylesheet" href="css/verificar/style.css" type="text/css" />
    </head>
    <body>

        <?php
    //Librerías para el envío de mail
    include_once('class.phpmailer.php');
    include_once('class.smtp.php');


    //Recibir todos los parámetros del formulario
    $para = $_POST['emailjefe-1'];


    $tipo_pase=$_POST['selected-1'];
    $fecha=$_POST['selected1-1'];
    $hora=$_POST['selected2-1'];
    $fecha1=$_POST['fecha_de_solicitud-1'];
    $nombre=$_POST['nombre_completo-1'];
    $empresa=$_POST['empresa-1'];
    $centro=$_POST['n_centro-1'];
    $numero_empleado=$_POST['num_empleado-1'];
    $depto=$_POST['departamento-1'];
    $puesto=$_POST['puesto-1'];
    $goce_primas=$_POST['goce_de_primas-1'];
    $motivo=$_POST['motivos-1'];
    $jefe=$_POST['jefe_inmediato-1'];
    $razones=$_POST['motivos-1'];



    //Este bloque es importante
    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->Host = "10.74.210.25";

    //Agregar destinatario
    $mail->From = ("[email protected]");
    $mail->FromName = "Recursos Humanos Gruver";
    $mail->Subject =  "RH-06 Solicitud de Ausencias y Retardos"; 

    $message.="<html>

    <body>
    <div class='table-responsive'>
     <table class='table table-bordered table-hover table-condensed'>
            <thead> 
                <tr> 
                     <th>Folio</th> 
                     <th>Fecha de la solicitud</th> 
                     <th>Numero de empleado</th> 
                     <th>Nombre y apellidos</th> 
                     <th>Empresa</th> 
                </tr> 
            </thead> 
            <tbody> 
                <tr> 
                    <td>00001</td> 
                    <td>".$fecha." </td> 
                    <td>".$numero_empleado." </td> 
                    <td>".$nombre."</td> 
                    <td>".$empresa."</td> 
                </tr>  
            </tbody> 

            <thead> 
                <tr> 
                    <th>Centro de trabajo</th> 
                    <th>Puesto</th> 
                    <th>Tipo de prima</th> 
                    <th>Tipo de pase (Entrada, Salida, o Falta)</th> 
                    <th>Fecha(s) a justificar</th> 
                 </tr> 
             </thead> 
            <tbody> 
                <tr> 
                     <td>".$centro."</td> 
                     <td>".$puesto."</td> 
                     <td>".$goce_primas." </td> 
                     <td>".$tipo_pase."</td> 
                     <td>".$fecha."</td>                                        
                </tr> 
            </tbody> 
            <thead> 
                 <tr> 
                    <th>Horarios</th> 
                    <th colspan='4' class='text-center'>Motivos</th> 
                </tr> 
            </thead> 
            <tbody> 
                <tr> 
                    <td>".$hora."</td> 
                    <td colspan='4' class='text-center'>>".$razones." </td> 
                </tr>             
            </tbody> 
        <tfoot> 
                <tr> 
                    <td colspan='5' class='text-center'>¿No son correctos los datos? <a href='index.php' target=''> Ingresa de nuevo los datos</a></td> 
                </tr> 
        </tfoot> 
     </table> 
    </body></html>";

    //FINALIZA CUERPO DEL PROGRAMA

    $mail->AddAddress($para);
    $mail->IsHTML(true);
    $mail->Body = $message;
    //Para adjuntar archivo
    $mail->AddAttachment($archivo['tmp_name'], $archivo['name']);
    $mail->MsgHTML($message);

    //Avisar si fue enviado o no y dirigir al index
    if($mail->Send())
    {
        echo'<script type="text/javascript">
                alert("Enviado Correctamente");
                window.location="http://10.74.210.251/mb/Proyecto_RH-06/index.php"
             </script>';
    }
    else{
        echo'<script type="text/javascript">
                alert("NO ENVIADO, intentar de nuevo");
            window.location="http://10.74.210.251/mb/Proyecto_RH-06/index.php"
             </script>';
    }
    ?>
</body>

'

    
asked by Juan Pablo Bustamante Luna 27.09.2016 в 15:46
source

2 answers

1

First, all the different mail services render their way:

Check the following link that contains lots of useful info

link

Secondly, I recommend Zurb Foundation to define the HTML:

link

    
answered by 27.09.2016 / 18:58
source
1

You can use an HTML template, when sending emails and you can create the file you want to send easier. I use them for

File to send mail

<?php 
    $error_bol=false;
    $error="";
    $enviado=2;
    if (isset($_GET["enviar"]))
    {


        if(!$error_bol)
        {

            $asunto=$correo_Subject14; //Asunto del correo, que tengo en constantes
            $body = utf8_decode(file_get_contents("plantillas_correo/".$plantilla_correo_partesiniestros));  //plantilla HTML, que voy a usar


            $campos=$campos . "nombrexxx,dnixxx,direccionxxx,municipioxxx,cpxxx,emailxxx,telefonoxxx,telefono2xxx,npolizaxxx,tipopolizaxxx,ciaxxx,fechaxxx,lugarxxx,descripcionxxx,danospropiosxxx,danosperjudicadoxxx,telefonoperjudicadoxxx,direccionperjudicadoxxx,localidadpewrjudicadoxxx,codigopostalxxx,tercerosxxx";
            $valores =$_POST["txtnombre"] . "," . $_POST["txtdni"] . "," .  $_POST["txtdireccion"] . "," .  $_POST["txtmunicipio"] . "," .  $_POST["txtcp"]. "," .  $_POST["txtemail"]. "," .  $_POST["txttelefono"]. "," .  $_POST["txttelefono2"]. "," .  $_POST["txtnpoliza"]. "," .  $_POST["cbotipopoliza"]. "," .  $_POST["cbocia"] . "," .  $_POST["txtfecha"] . "," . $_POST["txtlugar"] . "," .  $_POST["txtocurrido"]. "," .  $_POST["txtdanospropios"] . "," .  $_POST["txtperjudicado"]. "," .  $_POST["txttelefonoperjudicado"]. "," .  $_POST["txtdireccionperjudicado"]. "," .  $_POST["txtciudadperjudicado"]. "," .  $_POST["txtcpperjudicado"]. "," .  $_POST["txtdanosterceros"];

            $camp=explode(",",$campos);
            $val=explode(",",$valores);
            for ($i=0; $i<count($val); $i++)
            {
                $body = str_replace($camp[$i], utf8_decode(strtoupper($val[$i])), $body);   
            }


            $correo_NombreCliente= utf8_decode($_POST["txtnombre"]);
            $correo_destino_usado   = $correo_destino;
            if ($_POST["txtnombre"]==""){
                $enviado=0;
                $err_mail="Error en los datos introducidos";
            } else{
                include("enviar.php");
                if(!$mail->Send()) {
                    $enviado=0;
                    $err_mail=$mail->ErrorInfo;
                } else {
                    $enviado=1; 
                    header("Location: respmail.php");
                }
            }
        }
    }
?>

send.php

<?php

    require_once("includes/constantes.php");

            error_reporting(E_STRICT);
            date_default_timezone_set('Europe/Madrid');
            require_once('includes/class.phpmailer.php');
            //include("class.smtp.php");                                    // optional, gets called from within class.phpmailer.php if not 
                                                                            // already loaded
            $mail             = new PHPMailer();
            $mail->IsSMTP();                                                // telling the class to use SMTP
            $mail->Host       = $SERVIDOR_SMTP;                             // SMTP server
            $mail->SMTPDebug  = 1;                                          // enables SMTP debug information (for testing)
                                                                            // 1 = errors and messages
                                                                            // 2 = messages only
            $mail->SMTPAuth   = true;                                       // enable SMTP authentication
            $mail->Host       = $SERVIDOR_SMTP;                             // sets the SMTP server
            $mail->Port       = 25;                                         // set the SMTP port for the GMAIL server
            $mail->Username   = $correo_Usuario;                            // SMTP account username
            $mail->Password   = $correo_Clave;                              // SMTP account password
            $mail->SetFrom( $correo_Usuario, $correo_NombreCliente);
            $mail->AddReplyTo($correo, $correo_NombreCliente);
            $mail->AddCC($correo_copia,"");
            $mail->AddCC($correo_masana,"");
            if (isset($dirtemp)){
                 $mail->AddAttachment($dirtemp,"Parte del Siniestro");
            }
            //$mail->AddBCC($correo_administrativo, $correo_NombreAdministrativo);
            $mail->Subject    = strtoupper($asunto);
            $mail->MsgHTML($body);
            $address = $correo_destino_usado;

            //echo "direccion:".$address;

            $mail->AddAddress($address);


?>
    
answered by 27.09.2016 в 16:37