at(1) reads its command from standard input, so a pipe should work, but from the command as text, don't run the command as in your first example.
Check that the web server is allowed to run at(1), there is an at.deny and an at.allow file which might be blocking you (usually in /etc).
I suggest you try the at(1) command from the UNIX shell first, but make sure you are signed on as the same username that is executing your script.