Good evening community, I have a small error and I need help to solve it.
I need to make that when a customer makes a purchase of a product, the customer receives an email of the products they bought, I am doing it with codeigniter php, here I paste the code. It works perfectly for me with a single product, but if there are several, it only sends me the first product.
public function compra($correo,$idventa){
$detalle = $this->getDetalle($idventa);
$venta = $this->db->get_where('venta',['id' =>$idventa]);
// $cambio = $this->traerDatosCambio();
#### Generamos un string randomico para la nueva contraseña
$data_email = array();
$data_email["email_tipo"] = "comprar";
$data_email["email_remitente"] = $this->config["smtp_user"];
$data_email["email_destinatario"] = $correo;
$data_email["email_asunto"] = "[BeerCoin] Proceso de compra";
$message = "
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<meta name='viewport' content='width=device-width, initial-scale=1'>
<meta http-equiv='X-UA-Compatible' content='IE=edge' />
<style type='text/css'>
/* CLIENT-SPECIFIC STYLES */
body, table, td, a { -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }
table, td { mso-table-lspace: 0pt; mso-table-rspace: 0pt; }
img { -ms-interpolation-mode: bicubic; }
/* RESET STYLES */
img { border: 0; height: auto; line-height: 100%; outline: none; text-decoration: none; }
table { border-collapse: collapse !important; }
body { height: 100% !important; margin: 0 !important; padding: 0 !important; width: 100% !important; }
/* iOS BLUE LINKS */
a[x-apple-data-detectors] {
color: inherit !important;
text-decoration: none !important;
font-size: inherit !important;
font-family: inherit !important;
font-weight: inherit !important;
line-height: inherit !important;
}
/* MEDIA QUERIES */
@media screen and (max-width: 480px) {
.mobile-hide {
display: none !important;
}
.mobile-center {
text-align: center !important;
}
}
/* ANDROID CENTER FIX */
div[style*='margin: 16px 0;'] { margin: 0 !important; }
</style>
</head>
<body style='margin: 0 !important; padding: 0 !important; background-color: #eeeeee;' bgcolor='#eeeeee'>
<table border='0' cellpadding='0' cellspacing='0' width='100%'>
<tr>
<td align='center' style='background-color: #eeeeee;' bgcolor='#eeeeee'>
<!--[if (gte mso 9)|(IE)]>
<table align='center' border='0' cellspacing='0' cellpadding='0' width='600'>
<tr>
<td align='center' valign='top' width='600'>
<![endif]-->
<table align='center' border='0' cellpadding='0' cellspacing='0' width='100%' style='max-width:600px;'>
<tr>
<td align='center' valign='top' style='font-size:0; padding: 35px;' bgcolor='#044767'>
<!--[if (gte mso 9)|(IE)]>
<table align='center' border='0' cellspacing='0' cellpadding='0' width='600'>
<tr>
<td align='left' valign='top' width='300'>
<![endif]-->
<div style='display:inline-block; max-width:50%; min-width:100px; vertical-align:top; width:100%;'>
<table align='left' border='0' cellpadding='0' cellspacing='0' width='100%' style='max-width:300px;'>
<tr>
<td align='left' valign='top' style='font-family: Open Sans, Helvetica, Arial, sans-serif; font-size: 36px; font-weight: 800; line-height: 48px;' class='mobile-center'>
<h1 style='font-size: 36px; font-weight: 800; margin: 0; color: #ffffff;'>BeerCoins</h1>
</td>
</tr>
</table>
</div>
<!--[if (gte mso 9)|(IE)]>
</td>
<td align='right' width='300'>
<![endif]-->
<div style='display:inline-block; max-width:50%; min-width:100px; vertical-align:top; width:100%;' class='mobile-hide'>
<table align='left' border='0' cellpadding='0' cellspacing='0' width='100%' style='max-width:300px;'>
<tr>
<td align='right' valign='top' style='font-family: Open Sans, Helvetica, Arial, sans-serif; font-size: 48px; font-weight: 400; line-height: 48px;'>
<table cellspacing='0' cellpadding='0' border='0' align='right'>
<tr>
<td style='font-family: Open Sans, Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400;'>
<p style='font-size: 18px; font-weight: 400; margin: 0; color: #ffffff;'><a target='_blank' style='color: #ffffff; text-decoration: none;'>Shop </a></p>
</td>
<td style='font-family: Open Sans, Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 24px;'>
<a target='_blank' style='color: #ffffff; text-decoration: none;'><img src='https://www.tiindo-system.com/assets/img/email/shop.png' width='27' height='23' style='display: block; border: 0px;'/></a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<!--[if (gte mso 9)|(IE)]>
</td>
</tr>
</table>
<![endif]-->
</td>
</tr>
<tr>
<td align='center' style='padding: 35px 35px 20px 35px; background-color: #ffffff;' bgcolor='#ffffff'>
<!--[if (gte mso 9)|(IE)]>
<table align='center' border='0' cellspacing='0' cellpadding='0' width='600'>
<tr>
<td align='center' valign='top' width='600'>
<![endif]-->
<table align='center' border='0' cellpadding='0' cellspacing='0' width='100%' style='max-width:600px;'>
<tr>
<td align='center' style='font-family: Open Sans, Helvetica, Arial, sans-serif; font-size: 16px; font-weight: 400; line-height: 24px; padding-top: 25px;'>
<img src='https://www.tiindo-system.com/assets/img/email/check.png' width='125' height='120' style='display: block; border: 0px;' /><br>
<h2 style='font-size: 30px; font-weight: 800; line-height: 36px; color: #333333; margin: 0;'>
¡Gracias por ordenar!
</h2>
</td>
</tr>
<tr>
<td align='left' style='font-family: Open Sans, Helvetica, Arial, sans-serif; font-size: 16px; font-weight: 400; line-height: 24px; padding-top: 10px;'>
<p style='font-size: 16px; font-weight: 400; line-height: 24px; color: #777777;'>
Gracias por ordenar en BeerCoins tu cafeteria favorita. La siguiente orden fue:
</p>
</td>
</tr>
<tr>
<td align='left' style='padding-top: 20px;'>
<table cellspacing='0' cellpadding='0' border='0' width='100%'>
<tr>
<td width='75%' align='left' bgcolor='#eeeeee' style='font-family: Open Sans, Helvetica, Arial, sans-serif; font-size: 16px; font-weight: 800; line-height: 24px; padding: 10px;'>
Producto
</td>
<td width='25%' align='left' bgcolor='#eeeeee' style='font-family: Open Sans, Helvetica, Arial, sans-serif; font-size: 16px; font-weight: 800; line-height: 24px; padding: 10px;'>
Valor
</td>
</tr>";
THIS IS WHERE THE HEADACHE STARTS, the variable stored in $message2
foreach($detalle as $d){
$message2 = "<tr>
<td width='75%' align='left' style='font-family: Open Sans, Helvetica, Arial, sans-serif; font-size: 16px; font-weight: 400; line-height: 24px; padding: 15px 10px 5px 10px;'>"
.$d->producto."
</td>
<td width='25%'' align='left' style='font-family: Open Sans, Helvetica, Arial, sans-serif; font-size: 16px; font-weight: 400; line-height: 24px; padding: 15px 10px 5px 10px;''>
".$d->precio."
</td>
</tr>";
}
$message3 = "</table>
</td>
</tr>
<tr>
<td align='left' style='padding-top: 20px;'>
<table cellspacing='0' cellpadding='0' border='0' width='100%'>
<tr>
<td width='75%' align='left' style='font-family: Open Sans, Helvetica, Arial, sans-serif; font-size: 16px; font-weight: 800; line-height: 24px; padding: 10px; border-top: 3px solid #eeeeee; border-bottom: 3px solid #eeeeee;'>
TOTAL
</td>
<td width='25%' align='left' style='font-family: Open Sans, Helvetica, Arial, sans-serif; font-size: 16px; font-weight: 800; line-height: 24px; padding: 10px; border-top: 3px solid #eeeeee; border-bottom: 3px solid #eeeeee;'>
$". $venta->row()->total ."
</td>
</tr>
</table>
</td>
</tr>
</table>
<!--[if (gte mso 9)|(IE)]>
</td>
</tr>
</table>
<![endif]-->
</td>
</tr>
</table>
<!--[if (gte mso 9)|(IE)]>
</td>
</tr>
</table>
<![endif]-->
</td>
</tr>
</table>
<!-- LITMUS ATTRIBUTION -->
<!-- END LITMUS ATTRIBUTION -->
</body>
</html>
";
$data_email["email_mensaje"] = $message.$message2.$message3;
$data_email["preparado"] = 1;
$this->db->insert("dge_envio_email", $data_email);
$responce = array(0 => false, 1 => "Envio programado exitosamente");
return $responce;
}
I already tried to concatenate them with =+ and it sends me a 0 and I tried everything with the same name and it does not give me a record either. This is the closest solution I had, but it only shows me the first data fetched from the foreach
This is how the code was and working