I want you to email the product table

Asked

Viewed 270 times

0

I am trying to send a product table by php Mailer, but when I put the code of the table there, the values of the table are not filled, leaving only the codes appearing.

<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 codic 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>";
}
?>
  • No use sending external CSS code (.css) or putting Javascript in the email because it won’t work.

  • So what would be the solution to this?

  • I did not see in the form any field to be sent via POST.

  • Like I tried to put maias n got, can give an example of how I can put?

1 answer

0


If in your PHP you have

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

within 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 still within your form an input, button or javascript to submit the form. Example <input type='submit'>

Note that . css and . external js will not work, but you can put a style in the body of the message. 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 functions mysql_connect, mysql_fetch_assoc were deprecated in PHP 5.5.0 and the mysql_ * functions were removed in PHP7! Learn more with []

  • I could not place the table inside the text area

  • @Pottkermil_grau but what would be the table in your code that should be sent via post?

Browser other questions tagged

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