Random Number / Include in Confirmation Email

Hello. I am setting up a webpage form and use the below php as the form handler.
I’d like the PHP to generate a random “confirmation number”.
I also want the “confirmation number” to be included in the form that I receive via email as well as the confirmation email that is auto-generated and sent to the user. Any help?

[php]

<?php $subject = 'Register Me Today!'; $emailadd = '[email protected]'; $url = 'confirmation.html'; $req = '0'; $text = "Results from webpage:\n\n"; $space = ' '; $line = ' '; foreach ($_POST as $key => $value) { if ($req == '1') { if ($value == '') {echo "$key is empty";die;} } $j = strlen($key); if ($j >= 20) {echo "Name of form element $key cannot be longer than 20 characters";die;} $j = 20 - $j; for ($i = 1; $i <= $j; $i++) {$space .= ' ';} $value = str_replace('\n', "$line", $value); $conc = "{$key}:$space{$value}$line"; $text .= $conc; $space = ' '; } $headers = 'Cc: [email protected]' . "\r\n"; mail($emailadd, $subject, $text, 'From: '.$emailadd.'', $headers); $email = $_POST['Email']; $subject = 'We will be in contact with you shortly'; $text = 'Dear Business Owner, Your request for more information has been received. One of our representatives will be in contact with you shortly! For Your Records, your registration number is _________. .....blah blah blah '; // change text mail($email, $subject, $text, 'From: '.$emailadd.''); echo ''; ?>

[/php]

rand() is what you need.

@RaythXC

I’m somewhat of a newbie to PHP…where should I add it?

Apart from sending an email to an email account, what are you doing with data? I can’t see anywhere you are storing this.

I’m not storing it anywhere. It’s just a simple form handler, but once I get the email with the contact information from the form, I add it to a database (that is not on the server).

I searched the rand() function and it’s greek to me. There’s so many different ways of getting a random number, and I don’t know which is simplest.

I just want a 6-10 digit alphanumeric number to generate once they hit submit on the webform. Then I want that random number to appear both in the first email it sends to me with the contact info and in the second email it sends to the customer.

for 6 digits, simply

[php]
$number = rand(111111,9999999999);
[/php]

Then you just have to show $number in the email.

Thanks!

Sponsor our Newsletter | Privacy Policy | Terms of Service