First, don’t enqueue on the init
action. Enqueue on the wp_enqueue_scripts
action for the front end, or the admin_enqueue_scripts
action for the back end.
Second, the wp_ajax_*
action will only work for logged in users. For non-logged in users, you must use the wp_ajax_nopriv_*
action instead. If it needs to work for both, then you must hook both.
Finally, your jQuery.ajax call is missing the “action” of “send_message_to_customer” and the data is in the wrong format. Should look like this:
data: ['email_customer' : jQuery(this).attr("value") ],
action: 'send_message_to_customer',
Or possibly just jQuery(this).val()
instead of the attr() call there. Dunno, didn’t try the code myself to test that.