I can see only one problem right now but I don't think it's a reason for this error message: you use
$to
twice: in headers and first parameter in
mail
. You should not add it to headers as it is passes as a parameter anyway, the function call will do it.
I don't know exactly what to reason of the error. Are you sure the mail is properly set up in your Web server's host? This is one of "relay" problems.
Please see this discussion:
http://www.kirupa.com/forum/showthread.php?95806-503-Bad-sequence-of-commands-!-![
^].
—SA