示例#1
0
function SendHtmlEmail($plantilla, $variables, $subject, $destino, $origen = "*****@*****.**", $imagenes = NULL, $imgdir = "img", $html = NULL)
{
    require_once 'mail.php';
    if (!$html) {
        $smarty = SmartyInit();
        $smarty->assign("variables", $variables);
        $body = $smarty->fetch($plantilla);
    } else {
        $body = $html;
    }
    $mail = new htmlMimeMail();
    // Definimos el html
    $mail->setHtml($body);
    // Comprobamos si hay imagenes embebidas en el correo
    if ($imagenes != NULL) {
        // Leemos todos los ficheros y los aadimos al correo
        foreach ($imagenes as $imagen) {
            $len = strlen($imagen);
            $extension = substr($imagen, $len - 3, 3);
            if ($extension == "gif") {
                $tipo = "image/gif";
            }
            if ($extension == "jpg") {
                $tipo = "image/jpg";
            }
            $fichero = $imgdir . "/" . $imagen;
            $temp = $mail->getFile($fichero);
            $mail->addHtmlImage($temp, $imagen, $tipo);
        }
    }
    // Definimos las cabeceras de los mensajes
    $mail->setReturnPath($origen);
    $mail->setFrom($origen);
    $mail->setSubject($subject);
    $mail->setHeader('X-Mailer', 'Correo enviado por pachecoforja.com');
    // Enviamos el correo
    $result = $mail->send(array($destino), 'smtp');
    if (!$result) {
        return $mail->errors;
    } else {
        return true;
    }
}
示例#2
0
$attachment = $mail->getFile('example.zip');
/*
 * Get the contents of the example text/html files.
 * Text/html data doesn't have to come from files,
 * could come from anywhere.
 */
$text = $mail->getFile('example.txt');
$html = $mail->getFile('example.html');
/*
 * Add the text, html and embedded images.
 * The name (background.gif in this case)
 * of the image should match exactly
 * (case-sensitive) to the name in the html.
 */
$mail->setHtml($html, $text);
$mail->addHtmlImage($background, 'background.gif', 'image/gif');
/*
 * This is used to add an attachment to
 * the email. Due to above, the $attachment
 * variable contains the example zip file.
 */
$mail->addAttachment($attachment, 'example.zip', 'application/zip');
/*
 * Set the return path of the message
 */
$mail->setReturnPath('*****@*****.**');
/**
 * Set some headers
 */
$mail->setFrom('"Joe" <*****@*****.**>');
$mail->setSubject('Test mail');