Writing a PHP for this hard or easy?

I have failed in my attempts to write a PHP for this and get it to work correctly

You all seem extremly Intelligent and i am sure this is like adding 1 + 1 for you all

Could you look at the attachment action script and maybe give me some advise ??

Thanks, Shon