Esempio n. 1
0
/**
* Mail function (uses phpMailer)
* @param string From e-mail address
* @param string From name
* @param string/array Recipient e-mail address(es)
* @param string E-mail subject
* @param string Message body
* @param boolean false = plain text, true = HTML
* @param string/array CC e-mail address(es)
* @param string/array BCC e-mail address(es)
* @param array Images path,cid,name,filename,encoding,mimetype
* @param string/array Attachment file name(s)
* @return boolean Mail send success
*/
function vmMail($from, $fromname, $recipient, $subject, $body, $Altbody = '', $mode = false, $cc = NULL, $bcc = NULL, $images = null, $attachment = null, $replyto = null)
{
    global $mosConfig_debug;
    // Filter from, fromname and subject
    if (!vmValidateEmail($from) || !vmValidateName($fromname) || !vmValidateName($subject)) {
        return false;
    }
    $mail = vmCreateMail($from, $fromname, $subject, $body);
    if ($Altbody != "") {
        // In this section we take care for utf-8 encoded mails
        $mail->AltBody = vmAbstractLanguage::safe_utf8_encode($Altbody, $mail->CharSet);
    }
    // activate HTML formatted emails
    if ($mode) {
        $mail->IsHTML(true);
    }
    if ($mail->ContentType == "text/plain") {
        $mail->Body = vmAbstractLanguage::safe_utf8_encode($mail->Body, $mail->CharSet);
    }
    if (is_array($recipient)) {
        foreach ($recipient as $to) {
            if (vmValidateEmail($to)) {
                $mail->AddAddress($to);
            }
        }
    } else {
        if (vmValidateEmail($recipient)) {
            $mail->AddAddress($recipient);
        }
    }
    if (isset($cc)) {
        if (is_array($cc)) {
            foreach ($cc as $to) {
                if (vmValidateEmail($to)) {
                    $mail->AddCC($to);
                }
            }
        } else {
            if (vmValidateEmail($cc)) {
                $mail->AddCC($cc);
            }
        }
    }
    if (isset($bcc)) {
        if (is_array($bcc)) {
            foreach ($bcc as $to) {
                if (vmValidateEmail($to)) {
                    $mail->AddBCC($to);
                }
            }
        } else {
            if (vmValidateEmail($bcc)) {
                $mail->AddBCC($bcc);
            }
        }
    }
    if (!empty($replyto) && vmValidateEmail($replyto)) {
        $mail->AddReplyTo($replyto);
    }
    if ($images) {
        foreach ($images as $image) {
            $mail->AddEmbeddedImage($image['path'], $image['name'], $image['filename'], $image['encoding'], $image['mimetype']);
        }
    }
    if ($attachment) {
        if (is_array($attachment)) {
            foreach ($attachment as $fname) {
                $mail->AddAttachment($fname);
            }
        } else {
            $mail->AddAttachment($attachment);
        }
    }
    $mailssend = $mail->Send();
    if ($mosConfig_debug) {
        //$mosDebug->message( "Mails send: $mailssend");
    }
    if ($mail->error_count > 0) {
        //$mosDebug->message( "The mail message $fromname <$from> about $subject to $recipient <b>failed</b><br /><pre>$body</pre>", false );
        //$mosDebug->message( "Mailer Error: " . $mail->ErrorInfo . "" );
    }
    return $mailssend;
}
Esempio n. 2
0
 /**
  * This safely converts an iso-8859 string into an utf-8 encoded
  * string. It does not convert when the string is already utf-8 encoded
  *
  * @param string $text iso-8859 encoded text
  * @param string $charset This is a k.o.-Argument. If it is NOT equal to 'utf-8', no conversion will take place
  * @return string
  */
 function safe_utf8_encode($text, $charset)
 {
     if (strtolower($charset) == 'utf-8' && !vmAbstractLanguage::seems_utf8($text)) {
         // safely decode and reencode the string
         $text = utf8_encode($text);
     }
     // This converts the currency symbol from HTML entity to the utf-8 symbol
     // example:  &euro; => €
     $text = vmHtmlEntityDecode($text, null, vmGetCharset());
     return $text;
 }