예제 #1
0
function SendMail($From, $FromName, $To, $ToName, $Subject, $Text, $Html, $AttmFiles)
{
    // --------------
    // This function taken from www.PHP.net.
    // It was written by alex@bartl.net (29-Nov-2002 06:25)
    // Alex was inspired by the function of kieran.huggins@rogers.com (06-Nov-2002 04:52)
    // Note: it has been changed slightly to fit into the net2ftp application.
    // (Mainly the way error handling is done.)
    // --------------
    /* Alex's comments:
    This might be some useful stuff to send out emails in either text
    or html or multipart version, and attach one or more files or even
    none to it. Inspired by Kieran's msg above, I thought it might be 
    useful to have a complete function for doing this, so it can be used 
    wherever it's needed. Anyway I am not too sure how this script will
    behave under Windows.
    {br} represent the HTML-tag for line break and should be replaced,
    but I did not know how to not get the original tag  parsed here.
    function SendMail($From, $FromName, $To, $ToName, $Subject, $Text, $Html, $AttmFiles)
    $From      ... sender mail address like "*****@*****.**"
    $FromName  ... sender name like "My Name"
    $To        ... recipient mail address like "*****@*****.**"
    $ToName    ... recipients name like "Your Name"
    $Subject   ... subject of the mail like "This is my first testmail"
    $Text      ... text version of the mail
    $Html      ... html version of the mail
    $AttmFiles ... array containing the filenames to attach like array("file1","file2")
    */
    // -------------------------------------------------------------------------
    // Global variables
    // -------------------------------------------------------------------------
    global $net2ftp_result;
    // Initial tests
    //	$Html = $Html?$Html:preg_replace("/\n/","{br}",$Text) or die("neither text nor html part present.");
    //	$Text = $Text?$Text:"Sorry, but you need an html mailer to read this mail.";
    //	$From or die("sender address missing");
    //	$To or die("recipient address missing");
    if (strlen($Html) < 1 && strlen($Text) < 1) {
        $errormessage = __("You did not provide any text to send by email!");
        setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
        return false;
    }
    if (strlen($From) < 1) {
        $errormessage = __("You did not supply a From address.");
        setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
        return false;
    }
    if (strlen($To) < 1) {
        $errormessage = __("You did not supply a To address.");
        setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
        return false;
    }
    if (strlen($Html) < 1) {
        $Html = preg_replace("/\n/", "<br>", $Text);
    }
    // Check if the To email address is valid
    if (!eregi("^" . "[a-zA-Z0-9]+([_\\.-][a-zA-Z0-9]+)*" . "@" . "([a-zA-Z0-9]+([\\.-][a-zA-Z0-9]+)*)+" . "\\.[a-zA-Z]{2,}" . "\$", $To, $regs)) {
        $errormessage = __("The email address you have entered (%1\$s) does not seem to be valid.<br />Please enter an address in the format <b>username@domain.com</b>", $To);
        setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
        return false;
    }
    // Definition of some variables
    $OB = "----=_OuterBoundary_000";
    $IB = "----=_InnerBoundery_001";
    // Headers
    $headers = "MIME-Version: 1.0\r\n";
    $headers .= "From: " . $FromName . " <" . $From . ">\n";
    $headers .= "To: " . $ToName . " <" . $To . ">\n";
    $headers .= "Reply-To: " . $FromName . " <" . $From . ">\n";
    $headers .= "X-Priority: 1\n";
    $headers .= "X-MSMail-Priority: High\n";
    $headers .= "X-Mailer: My PHP Mailer\n";
    $headers .= "Content-Type: multipart/mixed;\n\tboundary=\"" . $OB . "\"\n";
    // Messages start with text/html alternatives in OB
    $Msg = "This is a multi-part message in MIME format.\n";
    $Msg .= "\n--" . $OB . "\n";
    $Msg .= "Content-Type: multipart/alternative;\n\tboundary=\"" . $IB . "\"\n\n";
    // Plaintext section
    $Msg .= "\n--" . $IB . "\n";
    $Msg .= "Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n";
    $Msg .= "Content-Transfer-Encoding: quoted-printable\n\n";
    // Plaintext goes here
    $Msg .= $Text . "\n\n";
    // Html section
    $Msg .= "\n--" . $IB . "\n";
    $Msg .= "Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n";
    $Msg .= "Content-Transfer-Encoding: base64\n\n";
    // Html goes here
    $Msg .= chunk_split(base64_encode($Html)) . "\n\n";
    // End of IB
    $Msg .= "\n--" . $IB . "--\n";
    // Attachments
    if ($AttmFiles) {
        foreach ($AttmFiles as $AttmFile) {
            //			$patharray = explode ("/", $AttmFile);
            //			$FileName=$patharray[sizeof($patharray)-1];
            $FileName = "RequestedFile.zip";
            $Msg .= "\n--" . $OB . "\n";
            $Msg .= "Content-Type: application/octet-stream;\n\tname=\"" . $FileName . "\"\n";
            $Msg .= "Content-Transfer-Encoding: base64\n";
            $Msg .= "Content-Disposition: attachment;\n\tfilename=\"" . $FileName . "\"\n\n";
            // File goes here
            $FileContent = local_readfile($AttmFile);
            if ($net2ftp_result["success"] == false) {
                return false;
            }
            $FileContent = chunk_split(base64_encode($FileContent));
            $Msg .= $FileContent;
            $Msg .= "\n\n";
        }
        // end for
    }
    // end if
    // Message ends
    $Msg .= "\n--" . $OB . "--\n";
    // Send mail
    $success2 = mail($To, $Subject, $Msg, $headers);
    if ($success2 == false) {
        $errormessage = __("Due to technical problems the email to <b>%1\$s</b> could not be sent.", $To);
        setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
        return false;
    }
    // Logging
    //syslog(LOG_INFO,"Mail: Message sent to $ToName <$To>");
}
예제 #2
0
// -------------------------------------------------------------------------
for ($i = 0; $i < sizeof($languagesArray); $i++) {
    // ------------------------------------
    // Send status
    // ------------------------------------
    echo "Language {$i} - " . $languagesArray[$i] . "<br />\n";
    flush();
    // ------------------------------------
    // Read the English file and get the lines
    // ------------------------------------
    $en_string = local_readfile($directory_old . "en" . $extension);
    $en_lines = explode_lines($en_string);
    // ------------------------------------
    // Read the old translated file
    // ------------------------------------
    $translated_old_string = local_readfile($directory_old . $languagesArray[$i] . $extension);
    $translated_old_lines = explode_lines($translated_old_string);
    // $en_lines contains:
    //    [694] => $net2ftp_messages["Zip"] = "Zip";
    //    [695] => $net2ftp_messages["Size"] = "Size";
    //    [696] => $net2ftp_messages["Search"] = "Search";
    // ------------------------------------
    // Initialize the translated string
    // ------------------------------------
    $translated_new_string = "";
    $translated_new_lines = array();
    // -------------------------------------------------------------------------
    // SUBLOOP: for all lines
    // -------------------------------------------------------------------------
    for ($j = 1; $j < sizeof($en_lines); $j++) {
        // ------------------------------------