Добрый вечер. Есть PHP форма отправки электронной почты. Она получает контент для всех полей (тема, адрес, текст письма) из мобильного приложения.
В входящем письме, русские символы письма отображается в виде "Ñ"ывÑ"ывÑ"Ñ‹Ð²Ñ "ывÑ"ывÑ"Ñ‹"
Код:
<?php
define('TO', ($_POST['email']));
//Change this to your message limit
define('LIMIT', 8000);
//Make sure all fields are included
if(!(
isset($_POST['message']) &&
isset($_POST['subject']) &&
isset($_POST['email']) &&
isset($_POST['name']) &&
isset($_POST['hash'])))
{
die('All fields must be filled');
}
//Defines message, subject, email, and name. Also prevents the use from sending HTML, and try email injection
$message = htmlentities(urldecode($_POST['message']));
$subject = urldecode($_POST['subject']);
$email = filter_var(urldecode($_POST['email']), FILTER_SANITIZE_EMAIL);
$name = urldecode($_POST['name']);
$hash = urldecode($_POST['hash']); //Get the MD5 hash from the URL that Unity sent
//Make sure the message is not too long
if(strlen($message) > LIMIT)
die('Message too long');
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
die('Invalid email');
//TODO: Add server side captcha checking
//Headers of the email
$headers = 'From: ' . $email . "rn" .
'Reply-To: ' . $email . "rn" .
'X-Mailer: PHP/' . phpversion();
//Generate an MD5 hash, depending on the values
$realHash = md5($email . $subject . SECRET_KEY);
//Compare the MD5 we generated to the one that Unity sent
if($realHash == $hash)
{
//Send the email
if(mail(TO, $subject . ' from ' . $name, $message, $headers))
{
//If the email was sent correctly, you can execute some code if you want. However, DON'T print anything.
}
else
{
//If the email failed to send, it does this
die('Failed to send message');
}
}
else
{
//If there was an error with the MD5 hash show a error
die('Error');
}
?>
Ищем помощь. Оплата по договоренности.
Опубликован 13.12.2016 в 19:12
Заказ находится в архиве