Gates , who once advocated talks with Tehran , said there may have been a missed opportunity in 2003 and 2004 in the immediate aftermath of the US invasion of Iraq when the more moderate Mohammed Khatami was president of Iran .