my codeigniter code is working fine for sending mail when the user fill a form and send it, the only issue is when the user has an email id with a special character in it like **Kurfürst@gmail.com or Müller@mail.com mail is not been sent below is my code it give form validation error
// ==================================================================================================
$emails = $this->Req_model->fetch_all_emails();
foreach($emails as $email){
mb_internal_encoding("UTF-8");
$subject = mb_encode_mimeheader($subject,'UTF-8','Q');
//$msg2 = "From: ".$userEmail."\n\n";
// $headers = "MIME-Version: 1.0" . "\r\n";
//$headers = "Content-type:text/plain;charset=UTF-8" . "\r\n";
$headers = "From: ".$userEmail . "\r\n";
// mb_internal_encoding("UTF-8");
// $headers = mb_encode_mimeheader($headers,'UTF-8','Q');
$msg2 = "Dienstleistung: ".$dep."\n";
$msg2 .= "Name: ".$surname."\n";
$msg2 .= "Telefon: ".$contact."\n";
$msg2 .= "E-Mail: ".$userEmail."\n";
$msg2 .= "Häufigkeit: ".$second_dropdown."\n";
$msg2 .= "Nachricht: ".$address."\n";
$msg2 = wordwrap($msg2,70);
mail($email['email'],"[sometext] Anfrage Dienstleistung ".$surname, $msg2, $headers);
}
below is my validation code
<script style="user-select: auto;">
$(document).on("click","#sumbitbtnform", function(e){
e.preventDefault()
var data = {}
if(!($("#department").val().length > 0) || !($("#userEmail").val().length > 0) || !($("#userName").val().length > 0) || !($("#second_dropdown").val().length > 0) || !($("#address").val().length > 0) || !($("#userContact").val().length > 0)){
$("#form-reject").css('display', "block")
const timeout = document.getElementById("form-reject")
setTimeout(hideElement, 2000) //milliseconds until timeout//
function hideElement() {
timeout.style.display = 'none'
}
}else{
let today = new Date();
let date = today.getDate()+'-'+(today.getMonth()+1)+'-'+today.getFullYear();
console.log("fjnskj")
data.department = $("#department").val()
data.email = $("#userEmail").val()
data.date = date
data.surname = $("#userName").val()
data.contact = $("#userContact").val()
data.address = $("#address").val()
data.service_interval = $("#second_dropdown").val()
var url = "https://mywebiste.com//requirements/req_form"
$.ajax({
url:url,
data: data,
method:"post",
success:function(dat){
console.log(dat)
$('#jobAddedSuccsessfuly').modal('show');
}
})
}
})
</script> ```
how can I solve it