The long-standing open problem of finding an upper bound for the Wiener index of a graph in terms of its order and diameter is addressed. Sharp upper bounds are presented for the Wiener index, and the related degree distance and Gutman index, for trees of order $n$ and diameter at most $6$.