I want to email the product table

0

I'm trying to send a table of products through the php Mailer , but when I put the table code there, the table values are not filled up,

<table width="467" border="1px" bgcolor="#CCC" >
    <thead>
    <tr>
        <th width="244" bgcolor="#CCC">Produto</th>
        <th width="89" bgcolor="#CCC">Quantidade</th>
        <th width="89" bgcolor="#CCC">Pre&ccedil;o</th>
        <th width="100" bgcolor="#CCC">SubTotal</th>
    </tr>
    </thead>
    <form action="?acao=up" method="post">
        <tbody>
            <?php
            error_reporting (E_ALL & ~ E_NOTICE & ~ E_DEPRECATED);
            if(count($_SESSION['checkout']) == 0){
                echo '
                <tr>
                    <td colspan="5">Não há produto no carrinho</td>
                </tr>
                ';
            }else{
                require("banco.php");
                $server = "localhost";
                $db = "clientes"; // Indique o nome do banco de dados que será aberto
                $usuario = "root"; // Indique o nome do usuário que tem acesso
                $password = ""; // Indique a senha do usuário   

                //1º passo - Conecta ao servidor MySQL
                $conect = mysql_connect($server,$user,$password ) or die (mysql_error());

                //2º passo - Seleciona o Banco de Dados
                $select_db = mysql_select_db($db) or die (mysql_error());
                $total = 0;
                foreach($_SESSION['checkout'] as $id => $qtd){
                $sql = "SELECT *  FROM produtos WHERE id= '$id'";
                $qr = mysql_query($sql) or die(mysql_error());
                $ln = mysql_fetch_assoc($qr);
                $nome = $ln['nome'];
                $preco = number_format($ln['preco'], 2, ',', '.');
                $sub = number_format($ln['preco'] * $qtd, 2, ',', '.');
                $total += $ln['preco'] * $qtd;
                echo '
                <tr>       
                    <td>'.$nome.'</td>
                    <td>'.$qtd.'</td>
                    <td>R$ '.$preco.'</td>
                    <td>R$ '.$sub.'</td>
                </tr>
                ';
            }
            $total = number_format($total, 2, ',', '.');
            echo '
            <tr>
                <td colspan="4">Total :
                    R$ '.$total.'
                </td>
            </tr>
            ';
            }
            ?>
        </tbody>
    </form>
</table>

This is the code of php Mailer :

<?php 
require "PHPMailer-master/PHPMailerAutoload.php";
$nome = $_POST['nome'];
$email = $_POST['email'];
$tabela = $_POST['tabela'];

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = '***********';                 // SMTP username
$mail->Password = '***********';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, 'ssl' also accepted
$mail->Port = 587;                                    // TCP port to connect to0

$mail->setFrom('[email protected]', '*******');
$mail->addAddress('***********');  
$mail->addAddress($email);    // Add a recipient
//$mail->addAddress('************');               // Name is optional
//$mail->addReplyTo('[email protected]', 'Information');
//$mail->addCC('[email protected]');
//$mail->addBCC('[email protected]');

//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML
$mail->Subject =  $email;
$mail->Body    = $nome;
$mail->Subject = "Compra efeituada com sucesso!!!";
$mail->Body  = "<!DOCTYPE html>
<html lang='pt-br'>
<head>
<meta charset='utf-8'/>
<meta content='width=device-width, initial-scale=1, maximum-scale=1' name='viewport'>
<title>Título da Página (Estrutura básica de uma página com HTML 5)</title>
<link href='css/seu-stylesheet.css' rel='stylesheet'/>
<script src='scripts/seu-script.js'></script>
</head>
<body>
<font color='black' face='arial'  size='4px'>Olá, $nome, $total<p>
<h3>Recebemos o seu pedido!</h3><p> Deposite Nessa Conta o Valor da compra: 4752564814 01 Apos o deposito entraremos em contato para o envio!
</font>
$tabela;
</html>
";

$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo"<center><font color = black>Email ou senha invalidos!!Aguarde um instante para tentar novamente.</font></center>";
    echo "<script>LoginFailed()</script>";
}else{
    echo"<center><h1><font color = black>Você foi autenticado com sucesso!Aguarde um instante que você sera redirecionado a pagina Home.</font></h1></center>";
    echo"<script>LoginSucessfully()</script>";
}
?>
    
asked by anonymous 01.10.2017 / 03:39

1 answer

0

If your PHP has

$nome = $_POST['nome'];
$email = $_POST['email'];
$tabela = $_POST['tabela'];

Inside your form should contain something like this:

  <input type="text" name="nome" value="Fulano">
  <input type="text" name="email" value="[email protected]">
  <textarea name="tabela"><table> tabela de produtos </table></textarea>

and even within your form an input, button or javascript to submit the form. Example <input type='submit'>

  

Note that external .css and .js files will not work, however you can put a style in the message body. Example:

<style type='text/css'>
  a,h3 {
  text-decoration : none;
  color : #0000FF;
  outline : 0;
} 
</style> 

In PHP put something like

if ((isset($_POST['email']))&&(!empty($_POST['email']))){
  require "PHPMailer-master/PHPMailerAutoload.php";
   .......
   .......
   .......


}
  

The mysql_connect , mysql_fetch_assoc functions were deprecated in PHP 5.5.0 and the mysql_ * functions were removed in PHP7! Learn more with

    
02.10.2017 / 00:11