A simple synthesis route to mesoporous carbons that contain heteroaromatic functionality is described. The sulfur-functionalized mesoporous carbon (S-FMC) materials that have been prepared show excellent thermal stability, as well as excellent hydrothermal stability, and stability over a wide range of pH values. These materials also show excellent mercury sorption performance over a broad range of pH, much broader than is possible with thiol-based functionality or most silica-based sorbents. The superior performance of these mesoporous heterocarbons as heavy-metal sorbent material is demonstrated. These materials are shown to be stable at elevated temperatures and extreme pHs, making them ideally suited as a new class of absorbent material.