Print Reseller Scheme
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

email form with reference number

Discussion in 'Website Design Forum:' started by Levi, Dec 17, 2011.

  1. Levi

    Levi Moderator Staff Member

    Ok... I'm finally getting round to doing my updated site (yeah yeah I know) and it's going to have a contact form, which I've managed to do...however I'd like to include an automatically generated, or replaced, reference code to go in the email header.

    Ideally it would say senders email address (got this) and in the header "Image Resolutions Contact Form Ref: abc123456" or something similar unless a code has been added into one of the fields. So say the field has "newcode123" entered the header would change to
    "Image Resolutions Contact Form Ref: newcode123".

    Pretty sure I need to use a database file to get this working but other than that it's above my current skills so does anyone know of an easy tutorial or instructions I could follow for this please :)

    edit: forgot - would like a copy to go to sender too :)
  2. Jazajay

    Jazajay Active Member

    Database file, pfff if you must, but you wont need it to get it working.
    Why do you need this though?

    Right did you use the form in my sig?
    If so you may need to modify this, but let me know if you get stuck with what you have and I'll give you a hand.

    First off add a new input tag and code it correctly using labels to your form, something like this will do:

    <label for="code">Code</label>
    <input type="text" name="code" id="code" />

    Then in your sending logic you will need something like this, any errors let me know as I am writing this off the cuff so haven't tested it:

    if(isset($_GET['code'])){ //Test to see if the code variable is set
    $cleanCode=''; //Set a cleaning variable to be used later.
    $code=$_GET['code']; //If it is set it to a variable to shorten the code
    if(ctype_alnum($code)){ //Test to see if it only equals [a-zA-Z0-9]
    if(empty($code)){ //If it is empty create a random numeric referance
    $cleanCode=mt_rand(); //Creates our random number
    }else{ //Else it is set and is not empty.
    $cleanCode=$code; //It is present and the data is clean, personally I would put a redundant safe guard in to follow the security in depth principle, let me know if you require one.
    }else{ //Else the code that was entered did not contain valid characters and thus I would class it as a hack attempt. So output a pleasant message.
    echo("Tut, tut, tut you tit you should not hack, someone has been a naughty boy or girl"); //Ideally you should collect thier IP address see what was entered and if it is code, add their IP to a dead IP list and add them to a loop logic which never gets this far in the processing for 1 hour but output errors and make it appear that it does. That way the hacker will be going round in circles and wont even realise it, but wont be doing any damage whatsoever.

    Then in your header/subject variable line just write:

    $subject="Jaz is amazing I know, I know ".$cleanCode; //We add the safe code variable to the header.

    And the code will appear in the header.
    Does that sort it?
    Let me know why you need it though as otherwise that is pretty pointless on its own.

    To send it to another email address just copy the mail(... line and change the to variable in that one to the one added in the form. test to see if it is present and not empty first of coarse, otherwise its not going anywhere.

    Any problems give me a shout.

    Purple - xHTML
    Red - Hypertext preprocessor
    Orange - comments
  3. Levi

    Levi Moderator Staff Member

    ok better give me a few days to get my head round that and included with my form.... suppose I better get my behind in gear now and do it properly lol

    As to why I want it... simples :)

    Basically sending files to me via email, php forms were/are limited to a few megs and files can hit several hundred megs in my line of work so the idea of a 'code' is to help with referencing and for the 'client' to send large files after the form has been sent (ie "please reply to the automated response message with any large files you feel may help in your query")

    Still debating on adding a file upload for small files too but the above is the main reasoning behind it :)

    And I will more than likely need your help at some point but we'll see how I go first, got to at least give it a go lol
  4. Jazajay

    Jazajay Active Member

    No worries, just give me a shout. :)

Share This Page