A possible solution is to use Javascript:
document.getElementById('sendmail').addEventListener('click', function(event){
event.preventDefault();
document.location.href = 'mailto:email@gmail.com';
});
<button id="sendmail">Send</button>
The same thing with jQuery:
$('#sendmail').on('click', function(event){
event.preventDefault();
document.location.href = 'mailto:email@gmail.com';
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button id="sendmail">Send</button>
Now, if the problem is not displaying the email in the source code, the solution is to make a request via AJAX:
PHP file:
<?php
if($logado)
exit(json_encode('email'=>'email@gmail.com');
Javascript:
$('#sendmail').on('click', function(event){
event.preventDefault();
$.ajax({
url: 'email.php',
dataType: 'json',
success: function(data){
document.location.href = 'mailto:' + data.email;
}
});
});
So the email will not be visible in the source, but nothing prevents the user from accessing the page email.php
and view the email. You can do security checks, but it would be meaningless, because from the moment the user clicks on the button, he will have access to the email. This can be a good solution against spam robots, that’s all.