If you do not need to add more text and just need to send the content of $MSG, you can replace
mail -s "$SUBJ" -q "$MSG" "$TO"
with
mail -s "$SUBJ" "$TO" < "$MSG"
The EOT
will be implicit in the <
construct. -q
is indeed only used to start a message. The rest is supposed to come through stdin.