Not a direct service. There's only one train a day from Pattaya to Bangkok (it arrives at 6:35pm) and you'd need to connect with the service to Surat Thani (the nearest station to Koh Phangan). There are bus services which transfer you from Surat Thani station to the ferry terminal for trips to Koh Samui and Koh Phangan.
Our friends at travelfish.org have a very comprehensive rundown on getting from Bangkok to the islands:
I guess you're going to a FMP? Have fun, but stay safe. Here's a little piece on the things to watch out for.
Phil over 8 years ago
Why going to Koh Phangan, it is really far away from Pattaya, it will take you one day just to go there. There are full moon parties totally crazy in Koh Samet and Koh Chang... check on the web for the dates. Koh Chang has full moon parties with buckets and everything you want for having a lot of fun, mushroom etc... but it is more relax and way more safe! almost 6 years ago