Skip to content

Instantly share code, notes, and snippets.

@pokisin
Last active September 10, 2019 05:05
Show Gist options
  • Save pokisin/e9ff84be60806b5db780bf4473ec461f to your computer and use it in GitHub Desktop.
Save pokisin/e9ff84be60806b5db780bf4473ec461f to your computer and use it in GitHub Desktop.
SendMail PHPMailer
include_once "phpmailer/class.phpmailer.php";
include_once "phpmailer/class.smtp.php";
public function sendmail($subject,$_mensaje,$to,$sucursal,$ruta){
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "juan@ejemplo.com"; // Cuenta de correo
$mail->Password = "*********"; //Password cuenta
$mail->SMTPDebug = false;
$mail->do_debug = 0;
// $mail->SMTPDebug = 2;
$mail->From = "juan@ejemplo.com";//de
$mail->FromName = "Es un ejemplo de etiqueta";//nombre
$mail->Subject = $subject;
$mail->AltBody = "Su cliente no soporta html";
//anexo de correos
$correos=explode(",",$to);
foreach ($correos as $correo) {
$mail->AddAddress($correo,"Sistema Excel.");
}
$mail->AddAttachment($ruta);
$mail->Body=$_mensaje;
$mail->IsHTML(true);
$status = 200;
if(!$mail->Send()) {//no envio
$respuesta['rs']="error";
$respuesta['desc']="error";
$status = 500;
}
else {//si envio
$respuesta['rs']="OK";
$respuesta['desc']="OK";
$status = 200;
}
/*---------------------------------------------------------*/
/*---------------------------------------------------------*/
echo "Email enviado correctamente";
}//end sendmailfilesdAction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment