Show html table format in the email body in sending

Asked

Viewed 201 times

0

I’m trying to show in the body of the email an html table with the products budgeted by the customer, but it’s going all disfigured.

What I’m doing in shipping is this:

$data_pedido = date("d-m-Y");
$hora = date("H:i:s");
$mostradata = substr($data_pedido,8,2).'/'.substr($data_pedido,5,2).'/'.substr($data_pedido,0,4); 
$assunto = "Orçamento";
// E-MAIL DO EMITENTE	
$auxRemetente = "email@cliente";
$headers = "MIME-Version: 1.1". PHP_EOL;
$headers .= "Content-type: text/html; charset=iso-8859-1". PHP_EOL;
$headers .= "From: $auxRemetente". PHP_EOL; // remetente
$headers .= "Cc: $auxRemetente". PHP_EOL;
$headers .= "Return-Path: $email". PHP_EOL; // return-path	
// CONFIGURAÇÃO DO CORPO DO E-MAIL
$message = " 
Orçamento\n
Data - $mostradata - Hora - $hora\r
Nome - $nome\r
CPF/CNPJ - $cpfcnpj\r
Empresa - $empresa\r
Telefone - $telefone\r
E-mail - $email\r
Mensagem - $observacao\r";	
$message .= '
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="margin:0 auto;border-collapse:collapse;">
   <tr>
      <td height="10">&nbsp;</td>
   </tr>
   <tr style="background:#A71930;color:#FFF;font-weight:bold;border:0px solid #FFFFFF" height="32">
      <td colspan="5" style="font-family: "Trebuchet MS", Arial; font-size: 13px; color: #FFF; padding-left:10px">
      PRODUTOS</td>
   </tr>
   <tr style="border-bottom:1px dashed #9f9f9f;background-color:#e1e1e1; font-family:Trebuchet MS, Arial; font-size: 15px; color: #9f9f9f">
      <td style="padding: 10px 0" align="center">ID</td>
      <td style="padding: 10px 0">Nome</td>
      <td style="padding: 10px 0" align="center">Quantidade</td>
   </tr>
   ';	
   $itens = count($_POST["itens"]);
   $NumItens = $itens;
   for($i=1;$i<=$NumItens;$i++) {
   $ProdID =  $_POST["item_id_{$i}"]; 
   $ProdDescricao = $_POST["item_descr_{$i}"]; 
   if ( isset($_SESSION["quantidade"][$ProdID]) && ($_SESSION["quantidade"][$ProdID] != 0) ){
   $ProdQuantidade = $_SESSION["quantidade"][$ProdID];
   }else{
   $ProdQuantidade = 1;
   }
   $message .= '
   <tr>
      <td style="padding: 10px; font-family:Trebuchet MS, Arial; font-size: 15px; color: #000" align="center">'.$ProdID.'</td>
      <td style="padding: 0px; font-family:Trebuchet MS, Arial; font-size: 15px; color: #000" align="left">'.$ProdDescricao.'</td>
      <td style="padding: 10px; font-family:Trebuchet MS, Arial; font-size: 15px; color: #000" align="center"">'.$ProdQuantidade.'</td>
   </tr>
   ';										
   }
   $message .= '
</table>
';
// ENVIO DA MENSAGEM
mail($email, $assunto, $message, $headers, "-f$auxRemetente");

What is being sent:

Data - 17/-2/15-0 - Hora - 15:27:04
Nome - Valter Ferreira Martins
CPF/CNPJ - 635.507.769-34
Empresa - Topdeia
Telefone - 4432333725
E-mail - [email protected]
Mensagem - Nada
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="margin:0 auto;border-collapse:collapse;">
   <tr>
      <td height="10">&nbsp;</td>
   </tr>
   <tr style="background:#A71930;color:#FFF;font-weight:bold;border:0px solid #FFFFFF" height="32">
      <td colspan="5" style="font-family: "Trebuchet MS", Arial; font-size: 13px; color: #FFF; padding-left:10px">
      PRODUTOS</td>
   </tr>
   <tr style="border-bottom:1px dashed #9f9f9f;background-color:#e1e1e1; font-family:Trebuchet MS, Arial; font-size: 15px; color: #9f9f9f">
      <td style="padding: 10px 0" align="center">ID</td>
      <td style="padding: 10px 0">Nome</td>
      <td style="padding: 10px 0" align="center">Quantidade</td>
   </tr>
   <tr>
      <td style="padding: 10px; font-family:Trebuchet MS, Arial; font-size: 15px; color: #000" align="center">1209</td>
      <td style="padding: 0px; font-family:Trebuchet MS, Arial; font-size: 15px; color: #000" align="left">BALAN�A ASA DELTA DA CARRETA P/ PINO � 61,5mm</td>
      <td style="padding: 10px; font-family:Trebuchet MS, Arial; font-size: 15px; color: #000" align="center"">78</td>
   </tr>
   <tr>
      <td style="padding: 10px; font-family:Trebuchet MS, Arial; font-size: 15px; color: #000" align="center">1219</td>
      <td style="padding: 0px; font-family:Trebuchet MS, Arial; font-size: 15px; color: #000" align="left">SUPORTE CENTRAL DO TRUCK</td>
      <td style="padding: 10px; font-family:Trebuchet MS, Arial; font-size: 15px; color: #000" align="center"">78</td>
   </tr>
</table>

  • Try using <br/> for line breaking

  • You had to have left Content-type: text/Plain in the question to make sense of the answer :)

1 answer

3


To send an email in HTML format, simply inform that it is of the type text/html

In this line

$headers .= "Content-type: text/plain; charset=iso-8859-1". PHP_EOL;

Has to be

$headers .= "Content-Type: text/html; charset=iso-8859-1". PHP_EOL;

Examples:

header("Content-Type: text/plain");
echo "<b>adventistapr</b>";
// saida: <b>adventistapr</b>

header("Content-Type: text/html");
echo "<b>adventistapr</b>";
// saida: adventistapr
  • Hello @Leo Caracciolo, thanks for the tip, but now the table appears but the text before it is in a line, no break.

  • puts the popular <br>

  • now it worked, thanks for the two tips.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.