Plugin index page code executes multiple times

The code in the file itself can be executed multiple times. If you want to do something when the plugin is activated use register_activation_hook and wrap your email sending codes in it.

function my_plugin_activation() {
   //Setting up the credential
    ...
 }
register_activation_hook( __FILE__, 'my_plugin_activation' );

error code: 523