Back to Home: PHP FormMail Generator I Need Help : Ask Question Without Registration

How to change the auto generated reference number for the email form and the form data records?
  • admin April 2011
    The form script will create a auto generated reference number for each submitted entry. The reference number is used as a order number or record ID. This number is generated by function phpfmg_getRecordID(). The function is defined in form.lib.php as follow :

    function phpfmg_getRecordID(){
        if( !isset($GLOBALS['RecordID']) ){
            $GLOBALS['RecordID'] = date("Ymd") . '-'.  substr( md5(uniqid(rand(), true)), 0,4 );
        };
        return $GLOBALS['RecordID'];
    }

    You can change the reference number by replacing the highlighted code above with your own code.

    If you only want to change the auto generated number for the email message. You can change it at the following code :

        // ... skip ...

        $RecordID  = phpfmg_getRecordID();

        // ... skip ...


        $_fields = array(
            '%NameOfSender%' => $fromName,
            '%FirstNameOfSender%' => $firstName,
            '%LastNameOfSender%' => $lastName,
            '%EmailOfSender%' => $from,
            '%TitleOfSender%' => $titleOfSender,
            '%DataOfForm%'   => $content,
            '%IP%'   => $_SERVER['REMOTE_ADDR'],
            '%Date%'   => date("Y-m-d"),
            '%Time%'   => date("H:i:s"),
            '%AutoID%' => $RecordID,
        );

    The $_fields variable is only for the email message, not for the form data records. You can also add your own new variables to here, then use them to your email message template. For example, you want to add a new variable %MyWebSite% like this :

        $_fields = array(

       '%NameOfSender%' => $fromName,

       '%FirstNameOfSender%' => $firstName,

       '%LastNameOfSender%' => $lastName,

       '%EmailOfSender%' => $from,

       '%TitleOfSender%' => $titleOfSender,

       '%DataOfForm%'   => $content,

       '%IP%'   => $_SERVER['REMOTE_ADDR'],

       '%Date%'   => date("Y-m-d"),

       '%Time%'   => date("H:i:s"),

       '%AutoID%' => $RecordID,

       "%MyWebSite%" => "http://" . $_SERVER['HTTP_HOST'],
        );



    Then use the variable for the email template :

    Dear %TitleOfSender% %NameOfSender%,

    Thank you for purchasing our product. Here is the copy of your order:
    %DataOfForm%

    We will contact you shortly.

    Regards,
    Sale Dept.

    IP: %IP%
    Date: %Date%
    Time: %Time%
    Reference ID: %AutoID%
    My website address : %MyWebSite%

    The email message will be replaced with the value you defined above.