Hello.
I have a working PHP Mail Form (thanks to this site). But when I recieve e-mails from users, there´s an issue.
If someone for instance writes "isn´t" in the textarea it shows up as "isn´t" in the mail that I recieve.

Here´s the header section of my HTML-file where the UTF is:

<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">

Here´s the HTML-form:

<form class="ajax-form" data-message-class="colors-e background-95 border heading" action="contact-form-handler.php" method="post" novalidate="novalidate" >
										<div class="row">
											<div class="col-md-6 control-group">
												<div class="alt-placeholder">Name</div>
												<input type="text" name="name" value="" size="40" placeholder="Name" data-validation-required-message="Please fill the required field." required>
												<div class="help-block"></div>
											</div>
											<div class="col-md-6 control-group">
												<div class="alt-placeholder">Email</div>
												<input type="email" name="email" value="" size="40" placeholder="Email" data-validation-required-message="Please fill the required field." required>
												<div class="help-block"></div>
											</div>
											<div class="col-md-12 control-group">
												<div class="alt-placeholder">Message</div>
												<textarea name="message" placeholder="Message" data-validation-required-message="Please fill the required field." required></textarea>
												<div class="help-block"></div>
											</div>
											<div class="col-md-12 form-actions">

And here´s the PHP:

<?php 
$myemail = 'contact@something.com';

$name = $_POST['name']; 
$email_address = $_POST['email']; 
$message = $_POST['message']; 

$successMessage = 'Message successfully sent!';

{
	$to = $myemail; 
	$email_subject = "Contact Form: $name";
	$email_body = " Noen har sendt en melding fra hjemmesiden! \n\n".
	" \n Navn: $name \n E-post: $email_address \n\n\n Melding: \n\n $message"; 
	
	$headers = "From: $myemail\n"; 
	$headers .= "Reply-To: $email_address";
	
	mail($to,$email_subject,$email_body,$headers);
	
}  
	echo($successMessage);

?>

Hope you guys can help me 😀

    How are you viewing the received email? Is that using UTF-8 encoding?

    Weedpacket Hello. I view them in Edge. The e-mail provider is Simply.com where the site hosted.
    About the UTF8, the header of the form mail page seems to adress the UTF8. Do I nead to refer to the UTF-coding somwere else. In adition to getting that symbol when typing an apostrophe, the scandinavian charakters allso show up as a bunch of symbols.

      Might want to send it as HTML. For instance, see https://www.php.net/manual/en/function.mail.php#example-3074 (but change the charset to utf-8). Then you might want to filter the input text through htmlentities() to html-encode special characters. (Might also want to replace newlines with <br> tags?)

      Or consider using something like PHPMailer which has functions just for that sort of thing.

      6 days later

      This is a character encoding issue. That apostrophe in your example isn´t is a multibyte character, probably encoded as UTF-8 at the point where someone enters the text. You need to make sure that you are consistent in which character sets you declare and use in numerous places:

      • point of data collection. For example an input form.
      • storage of the data, like in a database. your database should be declared with the same charset as your input form.
      • when you retrieve the data from wherever you store it. your database client, for example, should use the same charset for its query connection as you used in all prior steps
      • when you display the data. e.g., in a web page, in email, or saved to a text file.
        Write a Reply...