For some reason, a () backlash appear before every (') apostrophe when sending a HTML formatted email through the PHP mail(); function. It's not a typo or anything similar. I have checked with other symbols and it only occurs with the apostrophe. It's so weird. It happens within the parameter $message from the form textarea (Note it's not the whole content, as long as I know as my regex doesn't allow apostrophes anywhere else). Could this have to do with the UTF-8 encoding? It's just so weird. Has it ever happened to anyone else and is there any solution to it? It's not a big problem, it's just not a usual one.
$to = 'example@email.com';
$subject = "Hey, you've got a new message!";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <example@email.com>' . "\r\n";
$content = "<html><head><style>
.bold {
font-weight: bold;
}
.contiguous {
display: inline-block;
}
.correct-spacing {
white-space: pre-wrap;
}
.grey {
color: #373737;
}
.lilac {
color: #7b68ee;
}
</style></head><body>
<div class='bold contiguous lilac'>From: </div><div class='contiguous grey'>$name</div><br/>
<div class='bold contiguous lilac'>E-mail: </div><div class='contiguous grey'>$email</div><br/>
<div class='bold contiguous lilac'>Phone: </div><div class='contiguous grey'>$phone</div><br/><br/>
<div class='correct-spacing grey'>$message</div>
</body></html>";
mail($to, $subject, $content, $headers);
echo 'Your message has been sent. Thank you!';
Example of received email:
From: Name Example
E-mail: example@email.com
Phone: +123456789
Hi there,
This is a test. Let\'s hope it works.
Regards