Here's what you should do.
Before your form submits, assuming you are using JQuery based on your tag.
$('form').on('submit',function() {
var pmail = $('#pmail').val().trim()
var smail = $('#smail').val().trim()
if ( pmail === smail ) {
alert('Please enter an address different from your primary email in the secondary email');
return false;
}
});
<form action="/action" id="form-id">
<label for="pmail">Primary Email:
<input type="email" name="pmail" id="pmail" placeholder="example@example.com">
</label>
<label for="smail">Secondary Email:
<input type="email" name="smail" id="smail" placeholder="another@example.com">
</label>
<input type="submit" value="Submit Form">
</form>
Note the use of the
===
operator to check for comparison.