[thelist] building a dynamic variable in php

David U. davidu at everydns.net
Mon Jan 13 12:22:01 CST 2003


Tom Dell'Aringa wrote:
>
> Right, my bad guys. I have a send to friend list where they can send
> a link to 10 friends. Psuedocode:

w00 h00! More Spam!

>
> get 10 post variables as i
> if i is set
>    send a mail to i
> end

Okay.

>
> So I want the mail() code within the loop so I don't have to repeat
> the code, and just use variables for the data. The body and all that
> info is all the same except the receipient of course.

I hope register_globals is OFF.

>
> Does an array make sense in this context? Here is my current code:

It not only makes sense, to do it another way would NOT make sense.

> -------------------------------------------------
> for($i = 1; $i<=10; $i++)
> {
> $var = "mail" . $i;
> ${$var} = $_POST[$i];
>
> $body = "body of email";
>
> mail(${$var}, "From $personA/$personB", $body, "From:
> $email\r\nReply-To: $email\r\n");
> }
> --------------------------------------------------

I pray that register_globals is OFF in your setup.  Your method is going to
work but you should check out php.net/arrays

-davidu





More information about the thelist mailing list