Send Cart Session via email with PHPmailer

0

I have this code that shows the results of the items you have in the cart

<?php 
    session_start();
    require_once "functions/product.php";
    require_once "functions/cart.php";

    $pdoConnection = require_once "connection.php";

    if(isset($_GET['acao']) && in_array($_GET['acao'], array('add', 'del', 'up'))) {

        if($_GET['acao'] == 'add' && isset($_GET['id']) && preg_match("/^[0-9]+$/", $_GET['id'])){ 
            addCart($_GET['id'], 1);            
        }

        if($_GET['acao'] == 'del' && isset($_GET['id']) && preg_match("/^[0-9]+$/", $_GET['id'])){ 
            deleteCart($_GET['id']);
        }

        if($_GET['acao'] == 'limpar'){ 
            limpacart($_GET['id'], 1);
        }

        if($_GET['acao'] == 'up'){ 
            if(isset($_POST['prod']) && is_array($_POST['prod'])){ 
                foreach($_POST['prod'] as $id => $qtd){
                        updateCart($id, $qtd);
                }
            }
        } 
        header('location: carrinho.php');
    }

    $resultsCarts = getContentCart($pdoConnection);
    $totalCarts  = getTotalCart($pdoConnection);


?>

How can I send the items via email with PHPMailer?

// Instância do objeto PHPMailer
$mail = new PHPMailer;

$mail->CharSet = 'UTF-8';
$mail->SetLanguage("br");
$mail->Body = utf8_decode($body);

// Configura para envio de e-mails usando SMTP
$mail->isSMTP();

// Servidor SMTP
$mail->Host = 'mail.xxx.com.br';

// Usar autenticação SMTP
$mail->SMTPAuth = true;

// Usuário da conta
$mail->Username = '[email protected]';

// Senha da conta
$mail->Password = 'xxx@';

// Tipo de encriptação que será usado na conexão SMTP
$mail->SMTPSecure = 'ssl';

// Porta do servidor SMTP
$mail->Port = 465;

// Informa se vamos enviar mensagens usando HTML
$mail->IsHTML(true);

// Email do Remetente
$mail->From = '[email protected]';

// Nome do Remetente
$mail->FromName = $email_cart;

// Endereço do e-mail do destinatário
$mail->addAddress('[email protected]');

// Assunto do e-mail
$mail->Subject = 'xxxxx';

// Mensagem que vai no corpo do e-mail
$mail->Body = ' AQUI OS INTENS DO CARRINHO';

output

Array ( [0] => Array ( [id] => 1906 [name] => GLVC 3100 [price] => [quantity] => 1 [subtotal] => 0 ) [1] => Array ( [id] => 1907 [name] => HDRC 3153 [price] => [quantity] => 1 [subtotal] => 0 ) [2] => Array ( [id] => 2385 [name] => HDN 01 [price] => [quantity] => 1 [subtotal] => 0 ) [3] => Array ( [id] => 2390 [name] => HDN 06 [price] => [quantity] => 1 [subtotal] => 0 ) [4] => Array ( [id] => 2392 [name] => HDN 08 [price] => [quantity] => 1 [subtotal] => 0 ) [5] => Array ( [id] => 2421 [name] => Santa Ceia [price] => [quantity] => 1 [subtotal] => 0 ) [6] => Array ( [id] => 2422 [name] => Tartaruga [price] => [quantity] => 1 [subtotal] => 0 ) [7] => Array ( [id] => 2423 [name] => Tijolo [price] => [quantity] => 1 [subtotal] => 0 ) [8] => Array ( [id] => 2451 [name] => Argamassa Refrataria [price] => [quantity] => 1 [subtotal] => 0 ) [9] => Array ( [id] => 2452 [name] => Massa Refrataria em saca [price] => [quantity] => 1 [subtotal] => 0 ) )
    
asked by anonymous 27.08.2018 / 14:44

1 answer

0

Mounting a table, simple example:

# gera cabeçalho
$conteudo = '<table><tr><th>Nome</th><th>Preço</th><th>Qtd</th></tr>';
# gera conteúdo
foreach($array as $v) {
    $conteudo .= "<tr>";
    $conteudo .= "<td>$v['name']</td>";
    $conteudo .= "<td>$v['price']</td>";
    $conteudo .= "<td>$v['quantity']</td>";
    $conteudo .= "</tr>";
}
# fecha a table
$conteudo .= '</table>';

# inclui o conteúdo
$mail->Body = $conteudo;
    
27.08.2018 / 15:07