I'm aware there is a lot of topics like this one, but I wasn't yet able to find a satisfying answer.
PHP on a shared hosting where I have my webpage deletes backslashes (by using magic_quotes()
or something like that maybe?) from expressions that are soon to be sent using mail()
, so it changes this:
<?php
$email_to = "myemail@address.com";
$email_subject = "Message from your webpage";
$name = $_POST['name'];
$email_from = $_POST['email'];
$subject = $_POST['subject'];
$message= $_POST['message'];
if($subject) {
die(); // $subject is a honeypot
}
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
die();
}
$email_message = "";
$email_message .= "Name: ".$name;
$email_message .= "Email: ".$email_from;
$email_message .= "Message: ".$message;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion() . "\r\n";
$headers .= "From: " . $name . " <" . $email_from . ">" . "\r\n";
$headers .= "Reply-To: " . $email_from;
@mail($email_to, $email_subject, $email_message, $headers);
?>
into this:
$headers = 'MIME-Version: 1.0' . "rn";
$headers .= 'Content-type: text/html; charset=utf-8' . "rn";
$headers .= 'X-Mailer: PHP/'.phpversion()."rn";
$headers .= "From: " . $name . " <" . $email_from . ">" . "rn";
$headers .= "Reply-To: " . $email_from;
Such emails don't have an author and without proper charset, they look terrible. I tried many different functions, but none seemed to work. Does anyone know how to solve it?
EDIT: Ive put thw whole code in right now. Alse, var_export($headers) shows exactly whats been put in it string(136) "MIME-Version: 1.0rnContent-type: text/html; charset=utf-8rnX-Mailer: PHP/5.6.6rnFrom: dasda rnReply-To: asdasd@dasda.cz"