<?php
  include_once("email/htmlMimeMail.php");

  $lastemailerrors = array();

  function sendEmail($fromname, $fromemail, $toname, $toemail, $subject, $textbody, $htmlbody, $imagesdir = "./", $charset = "UTF-8") {
    global $lastemailerrors;
    $mailtosend = new htmlMimeMail();

    $mailtosend->setTextCharset($charset);
    $mailtosend->setHtmlCharset($charset);
    $mailtosend->setHeadCharset($charset);

    if ($htmlbody == "") {
      $mailtosend->setText($textbody);
    } else {
      $mailtosend->setHtml($htmlbody, $textbody, $imagesdir);
    }

    $mailtosend->setSubject($subject);
    $mailtosend->setFrom("\"".str_replace('"', "'", $fromname)."\" <$fromemail>");
    $mailtosend->setReturnPath($fromemail);
    $sendresult = $mailtosend->send(array("\"".str_replace('"', "'", $toname)."\" <$toemail>")/*, "smtp"*/);
    if (!$sendresult) {
      $lastemailerrors = $mailtosend->errors;     
      
    } else {
      $lastemailerrors = array();      
    }
    return $sendresult;
//    return $mailtosend->send(array("\"$toname\" <$toemail>"), "smtp");
  }  
 
