重置电子邮件主题的订单数量?

时间:2011-11-24 13:29:21

标签: php

我想向每个订单发送一封订单主题(#1),订单(#2)等的客户。当月初,它会在发送电子邮件时重置为订单(#1) ?

1 个答案:

答案 0 :(得分:0)

好的,让我们看看

<?php
    if(file_exists("id.txt")) {
        $storedID = unserialize(file_get_contents('id.txt')); 
    } else {
        $storedID = 1;
        $toStoreID = serialize($storedID);
        $handleID = fopen('id.txt','w+');
        fwrite($handleID, $toStoreID);
    }

    function sendEmail(){
        saveID();
        global $storedID;
        echo "Order No (".$storedID.")";
        // $to = "customer@domain.com";
        // $subject = "Hello "Order No (".$storedID.")";
        // $body = "Hi,\n\nTahnks God For Stackoverflow";
        // if (mail($to, $subject, $body)) {
        //  echo("<p>Message sent!</p>"); // Put saveID(); here so failed emails dosen't count !
        // } else {
        //  echo("<p>Message delivery failed</p>");
        // }
    }

    function saveID(){
        global $storedID;
        $today = date("d");
        if($today == 01 && file_exists("1st.txt")){
            $storedID = $storedID+1;
            $toStoreID = serialize($storedID);
            $handleID = fopen('id.txt','w+');
            fwrite($handleID, $toStoreID);
        } else if($today == 01 && !file_exists("1st.txt")){
            fopen('1st.txt','w+');
            $storedID = 1;
            $toStoreID = serialize($storedID);
            $handleID = fopen('id.txt','w+');
            fwrite($handleID, $toStoreID);
        } else {
            $storedID = $storedID+1;
            $toStoreID = serialize($storedID);
            $handleID = fopen('id.txt','w+');
            fwrite($handleID, $toStoreID);
        }
        if ($today != 01 && file_exists("1st.txt")){
            unlink("1st.txt");
            $toStoreID  = $toStoreID+1;
        }
        }

    sendEmail();

?>

我编写的最愚蠢的代码行(4分钟),无论如何都会完成这项工作:/