Add the 5th parameter to fix this.
$month = date("F", mktime(0, 0, 0, $m, 1));
It's the 31st, and only the months above have 31 days.
to clarify what happens, the default value for the 5th parameter is the current day. you pass a number higher than the number of days in that month, it rolls over to the next month.