Mail function bugfix