Forum Moderators: coopster

Message Too Old, No Replies

Unique Confirmation Number On Email Form

Need help with form

         

kurazi

7:10 pm on Dec 10, 2009 (gmt 0)

10+ Year Member



Does anyone know how to get a confirmation number sent to the person who fills out a form?
I have a form here, which one copy of what was filled out in the form gets sent to the person who filled it out, and one to the company, but I also need to someone give them a unique confirmation number with the email.
Anyone can point me in the right direction?


<?php
} else {
error_reporting(0);
$recipient = 'contact@example.ca';
$ID_Number = stripslashes($_POST['ID_Number']);
$Surname = stripslashes($_POST['Surname']);
$Given_name = stripslashes($_POST['Given_name']);
$Email_Address = stripslashes($_POST['Email_Address']);
$Contact_Change = stripslashes($_POST['Contact_Change']);
$Address = stripslashes($_POST['Address']);
$Municipality = stripslashes($_POST['Municipality']);
$Province = stripslashes($_POST['Province']);
$Postal_Code = stripslashes($_POST['Postal_Code']);
$Phone_Home = stripslashes($_POST['Phone_Home']);
$Phone_Work = stripslashes($_POST['Phone_Work']);
$Phone_Work_Extension = stripslashes($_POST['Phone_Work_Extension']);
$Card_Type = stripslashes($_POST['Card_Type']);
$CreditCardName = stripslashes($_POST['CreditCardName']);
$CardNumber = stripslashes($_POST['CardNumber']);
$CardNumber1 = stripslashes($_POST['CardNumber1']);
$CardNumber2 = stripslashes($_POST['CardNumber2']);
$CardNumber3 = stripslashes($_POST['CardNumber3']);
$Expiry_Month = stripslashes($_POST['Expiry_Month']);
$Expiry_Year = stripslashes($_POST['Expiry_Year']);
$Amount_Paid = stripslashes($_POST['Amount_Paid']);
$vet_clinic_name = stripslashes($_POST['vet_clinic_name']);
$Animal1_Name = stripslashes($_POST['Animal1_Name']);
$Rabies_Month_Animal1 = stripslashes($_POST['Rabies_Month_Animal1']);
$Rabies_Year_Animal1 = stripslashes($_POST['Rabies_Year_Animal1']);
$Animal2_Name = stripslashes($_POST['Animal2_Name']);
$Rabies_Month_Animal2 = stripslashes($_POST['Rabies_Month_Animal2']);
$Rabies_Year_Animal2 = stripslashes($_POST['Rabies_Year_Animal2']);
$Animal3_Name = stripslashes($_POST['Animal3_Name']);
$Rabies_Month_Animal3 = stripslashes($_POST['Rabies_Month_Animal3']);
$Rabies_Year_Animal3 = stripslashes($_POST['Rabies_Year_Animal3']);
$DogOrCat = stripslashes($_POST['DogOrCat']);
$Notes = stripslashes($_POST['Notes']);

$sendto = $_POST['Email_Address'];
$headers = "From: $recipient\r\n\r\n";
$subject = "Dog & Cat Tag Renewal";
$message = "Thank you for registering your pet with London Animal Care Centre.\n
Please keep this email as proof of your application for your
dog licence or cat identification tag.<br />

Your confirmation Id is \n

If you have any questions or concerns please call (800)555-1212
and have your confirmation id available.\n
Please allow 3 to 6 weeks for processing and delivery of your tags.\n

ID #: $ID_Number\r\n
Name: $Surname $Given_name\r\n
E-Mail Address: $Email_Address\r\n
Have you had a change in address or phone number over the last year?: $Contact_Change\r\n
Address: $Address\r\n
Municipality: $Municipality\r\n
Province: $Province\r\n
Postal Code: $Postal_Code\r\n
Phone # - Home: $Phone_Home\r\n
Phone # - Work: $Phone_Work\r\n
Work Ext: $Phone_Work_Extension\r\n
Card Type: $Card_Type\r\n
Name of Cardholder: $CreditCardName\r\n
Card #: #*$!X-#*$!X-#*$!X-$CardNumber3\r\n
Expiry Date: $Expiry_Month $Expiry_Year\r\n
Please indicate amount to be paid: $Amount_Paid\r\n
Veterinarian Clinic Name: $vet_clinic_name\r\n
Name of First Animal: $Animal1_Name\r\n
Month and Year of Vaccination: $Rabies_Month_Animal1 $Rabies_Year_Animal1\r\n
Name of Second Animal: $Animal2_Name\r\n
Month and Year of Vaccination: $Rabies_Month_Animal2 $Rabies_Year_Animal2\r\n
Name of Third Animal: $Animal3_Name\r\n
Month and Year of Vaccination: $Rabies_Month_Animal3 $Rabies_Year_Animal3\r\n
Breed Certification: $DogOrCat\r\n
Notes: $Notes\r\n
";
// Send mail to customer, refer to http://php.net/manual/en/function.mail.php
mail($sendto, $subject, $message, $headers);
if (!mail) {
echo "Message failed to send, please notify our Web Team.";
} else {
echo nl2br ("<center><br><br><br><br><br><br><br><br><br><br>Thank you. Your request has been sent and we will contact you shortly.<br><br><br><br><br><br><br><br><br><br></center>");
}
// Send mail to company
$to = "contact@example.ca"; // who gets this one?
$message = "Thank you for registering your pet with London Animal Care Centre.\n
Please keep this email as proof of your application for your
dog licence or cat identification tag.<br />

Your confirmation Id is \n

If you have any questions or concerns please call (800)555-1212
and have your confirmation id available.\n
Please allow 3 to 6 weeks for processing and delivery of your tags.\n

ID #: $ID_Number\r\n
Name: $Surname $Given_name\r\n
E-Mail Address: $Email_Address\r\n
Have you had a change in address or phone number over the last year?: $Contact_Change\r\n
Address: $Address\r\n
Municipality: $Municipality\r\n
Province: $Province\r\n
Postal Code: $Postal_Code\r\n
Phone # - Home: $Phone_Home\r\n
Phone # - Work: $Phone_Work\r\n
Work Ext: $Phone_Work_Extension\r\n
Card Type: $Card_Type\r\n
Name of Cardholder: $CreditCardName\r\n
Card #: $CardNumber $CardNumber1 $CardNumber2 $CardNumber3\r\n
Expiry Date: $Expiry_Month $Expiry_Year\r\n
Please indicate amount to be paid: $Amount_Paid\r\n
Veterinarian Clinic Name: $vet_clinic_name\r\n
Name of First Animal: $Animal1_Name\r\n
Month and Year of Vaccination: $Rabies_Month_Animal1 $Rabies_Year_Animal1\r\n
Name of Second Animal: $Animal2_Name\r\n
Month and Year of Vaccination: $Rabies_Month_Animal2 $Rabies_Year_Animal2\r\n
Name of Third Animal: $Animal3_Name\r\n
Month and Year of Vaccination: $Rabies_Month_Animal3 $Rabies_Year_Animal3\r\n
Breed Certification: $DogOrCat\r\n
Notes: $Notes\r\n
";
mail($to, $subject, $message, $headers);
if (!mail) {
echo "Message failed to send. Please notify our Web Team.";
} else {
// something here to notify the web team if it fails.
}
}
?>

[edited by: coopster at 4:27 am (utc) on Dec. 17, 2009]
[edit reason] removed specifics [/edit]

CyBerAliEn

10:38 pm on Dec 10, 2009 (gmt 0)

10+ Year Member



If all you need is a random set of characters as the "confirmation ID" (and it doesn't really matter what it is; you're just as using it as an 'extra' piece of info), the following may prove useful...


<?php
$code1 = rand(1000,9999);
$code2 = time();
$code3 = md5(time());
?>

code1 - will return a 4-digit integer number. You can add more '0' or '9' to increase number of digits. The first argument is the lower specification, 2nd argument is upper specification.

code2 - will return UNIX timestamp of current time. It will be a number such as: 1260468765 .

code3 - this will take the UNIX time as an input, and then hash it via PHP's MD5 algorithm. Huh? It basically just returns a unique string, corresponding to the input. In other words, as long as the input changes (is different, never the same), you are incredibly unlikely to get the same output. This makes it semi-unique (though not 100%). It will look something like "cdf31fb11045de4bb063e418ff6b2ea0". To make it more professional, you could do something like

$code = strtoupper(md5(time()));
to make all the letters uppercase. You could even use other PHP functions to "split" the string into chunks, with a dash (-) imbetween every 4 characters; etc.

[u]Now if you want a truly UNIQUE, random confirmation ID, there is a bit more work.[/u] You can use all of the above methods to generate an ID. But then you will need to store the IDs you'd used (generally by storing them as entries in a database). Then, when you create a code... you'd have to change the programming such that: it checks if the code is unique, if it is, it uses it; if the code is not unique, re-generate a code, and try again. Pretty simple really... but it is extra work to get a database table running.

Were it me, this is what I would do...
I'd use code3, with PHP making the string uppercase and maybe splitting it into chunks (ie: "#*$!X-#*$!X-#*$!X"). Since the input is the unix timestamp, and this is always changing (incrementing upwards with time passing)... I am guaranteed ~reasonably~ (not 100% exactly!) that the output from MD5 will always be unique (in my opinion, unique-enough). Hence, I really wouldn't need to worry about it clashing with another ID too often (if at all). Then, you and customers would have an ID to reference. To further "decrease your risk", if you ever had to use the ID (example: looking up an order)... you could just ask for their name and this ID number (the odds of these 2 items ever matching is ~0). BUT... if I needed to be sure each ID was 100% unique; I'd employ the same method but with a database to record every ID used and program it to check against the DB before issuing a new ID.

Best of luck!