Viewing file: enviar_mail.php (3.75 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
//Definimos las propiedades y llamamos a los métodos
require_once('3ros/phpmailer/class.phpmailer.php');
$mail = new phpmailer();//instanciamos un objeto de la clase phpmailer
$mail->PluginDir = "3ros/phpmailer/";
if(!empty($datos_correo['smtpsecure'])){ $mail->SMTPSecure = $datos_correo['smtpsecure']; }
$mail->Mailer = $datos_correo['mailer']; //servidor smtp
$mail->SMTPAuth = $datos_correo['smtpauth']; //indicamos autenticación
$mail->Host = $datos_correo['host']; //nombre de nuestro servidor smtp ej. "mail.diariosanrafael.com.ar"
$mail->Port = $datos_correo['port'];
$mail->Username = $datos_correo['username']; //nombre de usuario y password
$mail->Password = $datos_correo['pass'];
$mail->From = $datos_correo['fromemail']; //nuestra dirección de correo y el nombre veran
$mail->FromName = $datos_correo['fromname'];
$mail->Timeout = $datos_correo['timeout'];
$mail->IsHTML(true);
if(!empty($datos_correo['replyto'])){
$mail->AddReplyTo($datos_correo['replyto']);
}elseif(!empty($parametros['reply_email'])){
$mail->AddReplyTo($parametros['reply_email'], $parametros['reply_nombre']);
}
$mail->AddAddress($parametros['correo_destino']); //dirección destino
if (!empty($parametros['adjunto'])){
$mail->AddAttachment($parametros['adjunto']);
}
if(!empty($parametros['cco_email'])){
$mail->AddBCC($parametros['cco_email']);
}
$mail->Subject = $parametros['asunto'];
$mail->Body = '<div style="background-color: rgb(226, 226, 226); width: 100%; min-height: 400px; color: rgb(35, 31, 32); font-family: Calibri, Helvetica, Arial, sans-serif; font-size: 14px; background-position: 50% 0%; background-repeat: repeat no-repeat;">
<div align="center" style="width: 100%; margin: 0px auto; padding-top: 30px;">
<table style="padding: 0px; margin: 0px; border-collapse: collapse; empty-cells: hide; width: 100%;">
<tbody>
<tr>
<td style="padding: 0px;">
<div style="text-align: center; min-height: 18px; padding-top: 0px; padding-right: 0px; padding-bottom: 20px !important; padding-left: 0px; width: 100%; margin: 0px; font-weight: bold; color: rgb(35, 31, 32); font-size: 30px !important;">
<span style="margin-left: 4px; margin-right: 4px;">'.$parametros['encabezado_mensaje'].'</span>
</div>
<div style="vertical-align: top; width: 90%; margin: 0px auto; padding: 0px !important;">
<div style="padding: 15px 10px; margin: 0px; border: 1px solid rgb(188, 187, 193); background-color: rgb(255, 255, 255);">
'.$parametros['contenido_mensaje'].'
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>';
$mail->AltBody = $parametros['encabezado_mensaje_txt'].'
'.$parametros['contenido_mensaje_txt'];
//se envia el mensaje, si no ha habido problemas la variable tendra el valor true
try {
$exito = $mail->Send();
if(!$exito){
$error = "Error al enviar correo a ".$parametros['correo_destino']." al host ".$mail->Host.": ".$mail->ErrorInfo;
toba::notificacion()->agregar($error, "error");
return false;
}else{
$mail->ClearAddresses();
#toba::notificacion()->agregar("Este correo puede ingresar en la casilla de correo no deseado, por favor verificalo.", "info");
return true;
}
} catch (Exception $e) {
$error = "Error al enviar correo a ".$parametros['correo_destino']." al host ".$mail->Host.": ".$e;
toba::notificacion()->agregar($error, "error");
return false;
}
?>
|