Send to different recipients Php Mailer

1

I am doing a generated order, and when this is correct send an email to the client with acknowledgments and the corresponding invoice. But you would need that at the same time send an email to another address that would be the administration so that they know that they have received a new order. Of course, the message must be different.

This is how I have it now:

$html = ob_get_contents();
ob_end_clean();
$html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8');
//$html = str_replace("�", "Á", $html);

require_once 'dompdf/autoload.inc.php';
use Dompdf\Dompdf;
$dompdf = new DOMPDF();
$dompdf->setPaper('A4', 'portrait');
$dompdf->loadHtml($html);

ini_set("memory_limit","64M");
$dompdf->render();
$pdf = $dompdf->output();
file_put_contents("facturas/".$facturaid.".pdf", $pdf);
/* ENVIO DE PDF POR CORREO ELECTRÓNICO */
include "plantillaEmail/templatePedido.php";
include "PHPMailer/class.phpmailer.php";
include "PHPMailer/class.smtp.php";

$email_user = "[email protected]";
$email_password = "pass";
$the_subject = "Factura " . $facturaid;
$address_to = $usuariosArray['Username'];
$from_name = "Depildiodo";
$phpmailer = new PHPMailer();
// ---------- datos de la cuenta de Gmail -------------------------------
$phpmailer->Username = $email_user;
$phpmailer->Password = $email_password;
//-----------------------------------------------------------------------
// $phpmailer->SMTPDebug = 1;
$phpmailer->CharSet = 'UTF-8';
$phpmailer->SMTPSecure = 'ssl';
$phpmailer->Host = "mail.depildiodo.com"; // GMail
$phpmailer->Port = 465;
$phpmailer->IsSMTP(); // use SMTP
$phpmailer->SMTPAuth = true;
$phpmailer->setFrom($phpmailer->Username,$from_name);
$phpmailer->AddAddress($address_to); // recipients email
$phpmailer->Subject = $the_subject;
$phpmailer->Body = $body;
$phpmailer->AddAttachment("facturas/".$facturaid.".pdf",
                     $facturaid.".pdf");
$phpmailer->IsHTML(true);
$phpmailer->Send();
$_SESSION['carrito']= array();
if($redireccion != ""){
  header('Location: '.$redireccion, true, 301);
}else {
header('Location: index.php', true, 301);
}

Any suggestions please?

    
asked by Miguel 03.01.2019 в 13:42
source

1 answer

0

You can encapsulate everything as a function that has the necessary parameters (the recipient) and then invoke it the times you occupy it with different parameters.

I can think of something quick this way.

function enviarCorreo($correo, $contenido){
      //codigo de enviar correo 
 return true;
}
    
answered by 03.01.2019 в 15:48