Código PHP:
/*
* bool revisar_tipo();
* Funcion encargada de revisar que los contenidos y caracteristicas
* del correo sean validas.
*/
function revisar_tipo(){
if (empty($this->mail_to)){
$this->debug("No existe una direccion de destinatario");
return false;
}
$this->mail_type = 0;
$this->buscar_imagenes();
if (!empty($this->mail_text)){
$this->mail_type = $this->mail_type + 1;
}
if (!empty($this->mail_html)){
$this->mail_type = $this->mail_type + 2;
if (empty($this->mail_text)){
$this->mail_text = strip_tags(eregi_replace("<br>", SALTO, $this->mail_html));
$this->mail_type = $this->mail_type + 1;
}
}
if ($this->adjuntos_indice != 0){
if (count($this->adjuntos_img) != 0){
$this->mail_type = $this->mail_type + 8;
}
if ((count($this->adjuntos) - count($this->adjuntos_img)) >= 1){
$this->mail_type = $this->mail_type + 4;
}
}
return true;
}
/*
* void buscar_imagenes();
* Se encarga de encontrar (si existen) imagenes embebidas en html
*/
function buscar_imagenes(){
if ($this->adjuntos_indice != 0){
foreach($this->adjuntos as $key => $valor){
if (eregi('image', $this->adjuntos[$key][tipo]) && eregi('<img.*src=[\"|\'](' . $this->adjuntos[$key][nombre] . ')[\"|\'].*>', $this->mail_html)){
$img_id = md5($this->adjuntos[$key][nombre]) . ".nxs@mimemail";
$this->mail_html = eregi_replace('(<img.*src=[\"|\'])(' . $this->adjuntos[$key][nombre] . ')([\"|\'].*>)', '\\1cid:' . $img_id . '\\3', $this->mail_html);
$this->adjuntos[$key][embebido] = $img_id;
$this->adjuntos_img[] = $this->adjuntos[$key][nombre];
}
}
}
}
/*
* bool valida_correo(string $correo);
* Funcion encargada de validar si la direccion de correo es
* valida 'sintacticamente'
*/
function valida_correo($correo){
if (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.'@'.'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$',$correo)){
return true;
}
$this->debug("Correo no válido sintacticamente ($correo)");
return false;
}
/*
* string revisar_mime(string $nombre);
* Funcion que trata de determinar el tipo MIME por el nombre
* de archivo mandado, en caso de no encontrar se regresa el
* predeterminado
*/
function revisar_mime($nombre){
$ext_array = explode(".", $nombre);
if (($ultimo = count($ext_array) - 1) != 0){
$ext = $ext_array[$ultimo];
foreach($this->tipos_mime as $key => $valor){
if ($ext == $key){
return $valor;
}
}
}
return "application/octet-stream";
}
/*
* int abrir_archivo(string $archivo);
* Abre el contenido de una archivo y lo devuelve
* $archivo - Ruta donde se encuentra el archivo a abrir
*/
function abrir_archivo($archivo){
if($fp = fopen($archivo, 'r')){
$regresar = fread($fp, filesize($archivo));
fclose($fp);
return $regresar;
}
return false;
}
/*
* void debug(string $msg);
* Funcion para el manejo de errores de la clase.
*/
function debug($msg){
if ($this->msg_error == "si"){
echo "<br><b>Error:</b> " . $msg . "<br>";
}
elseif ($this->msg_error == "halt"){
die ("<br><b>Error:</b> " . $msg . "<br>");
}
return false;
}
}
?>
BUENO, AQUI TERMINA EL ARCHIVO!!!!
PERO NO TE ASUSTES, ESTO ES SOLO LA CLASE QUE SE ENCARGA DE SIMULAR LO QUE TU TIENES.
Basta con que guardes todo eso en un archivo llamado
nxs_mimemail.inc.php
Y lo usuas así...
Código PHP:
include ("nxs_mimemail.inc.php");
$correo=new nxs_mimemail;
$correo->asunto("Promocion para ".$nombreempresa);
$correo->correo_de("[email protected]", "Nombre");
$correo->agregar_para("[email protected]");
$correo->agregar_cc("[email protected]");
$correo->mensaje_texto($mensajeTXT);
$correo->mensaje_html($mensajeHTML);
$correo->enviar();
Y listo!!!