I wrote this php email sender code:
<?php
if($_SERVER["REQUEST_METHOD"] === "POST") {}
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['mail'];
$phone = $_POST['phone'];
$company = $_POST['company'];
$website = $_POST['website'];
$message = $_POST['message'];
$recaptcha_secret = "xy";
$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$recaptcha_secret."&response=".$_POST['g-recaptcha-response']);
$response = json_decode($response, true);
if($response["success"] === true){
$mailTo = "[email protected]";
$headers = "From: ".$mailFrom;
$txt = "Feladó: ".$name."nTelefonszám: ".$phone."nCég: ".$company."nWeboldal: ".$website."nnÜzenet: ".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: feedback/koszonjuk");
}else{
header("Location: feedback/error");
}
}
?>`
It sends email to my server side email address after someone fill out my form on my website with recaptcha.
I want to have the emails in UTF-8 character coding, but I can not see the issue. These characters are mismanaged in the emails from the form: öüóőúéá
The HTML page where the form is located is set to UTF-8.
The HTML form code:
<form action="ajanlatkeres.php" method="post" class="ajanlatkeres-form" accept-charset="utf-8">
<h2>Általános adatok</h2>
<input type="text" name="name" placeholder="Teljes név*" class="feedback-input" required>
<input type="text" name="mail" placeholder="E-mail*" class="feedback-input" required>
<input type="text" name="phone" placeholder="Telefonszám*" class="feedback-input" required>
<h2>Vállalkozás adatai</h2>
<input type="text" name="company" placeholder="Márkanév" class="feedback-input">
<input type="text" name="website" placeholder="Weboldal" class="feedback-input">
<h2>Üzenet</h2>
<input type="hidden" name="subject" value="Ajánlatkérés">
<textarea name="message" placeholder="Írj pár sort projektedről*" class="feedback-input" required></textarea>
<div class="g-recaptcha" id="rcaptcha" data-theme="dark" data-sitekey="xy"></div>
<br/>
<button id="submit_form" class="contactbutton" type="submit" name="submit">Küldés</button>
</form>
What can cause this issue? Is it in my php code?
2
Answers
You can try changing the header:
and
Try to set
content-type and character encoding
in headers