Since you are writing the code, you write it in the code in plain text. This is exactly the same as I do with my VB and Access error routines.
error_function($sql, "main.php, query 2, line 43", mysql_error(), "user message");
All my Access applications store the errors in a table for me so I can fault-find user reported errors easily, and tell what they were doing when it happened. I assume that you are trying to do the same thing. Write your general error reporting function so that it accepts what you need and pass the info every time you call it. Written properly, it will be resuable for the next 10 years in every project you write. In your case it will email you instead of saving in a db, so you should probably get it to also log the data on the server.