Результаты контактной формы отображаются в другом формате - PullRequest
1 голос
/ 02 июля 2019

Привет, ребята. У меня возникла проблема, когда моя контактная форма возвращает результаты в другом текстовом формате, и мне было интересно, возможно, что-то не так с моим заголовком в моей контактной форме php.

Я получаю такие результатыкак:.

Я попытался преобразовать текст и посмотреть, является ли он текстом, потому что мы получаем спам по электронной почте время от времени

<?php
/*
THIS FILE USES PHPMAILER INSTEAD OF THE PHP MAIL() FUNCTION
*/

require 'PHPMailer-master/PHPMailerAutoload.php';

// an email address that will be in the From field of the email.
$fromEmail = 'eleccon@global.co.za';*/
$fromEmail = $_POST['email'];
$fromName = $_POST['name'];



/**Add Subject in header area of contact form**/

// an email address that will receive the email with the output of the 
form
$sendToEmail = 'travelwithus@fellengtours.com';
$oldEmail = 'eleccon@global.co.za';
$sendToName = 'Felleng Tours';

// subject of the email
/*$subject = 'Felleng Tours contact form';*/
$subject = $_POST['subject'];

// form field names and their translations.
// array variable name => Text to appear in the email
$fields = array('name' => 'Name', 'email' => 'Email', 'subject' => 
'Subject', 'message' => 'Message');

// message that will be displayed when everything is OK :)
$okMessage = '<strong>Contact form successfully submitted. Thank you, I 
will get back to you soon!</strong>';

// If something goes wrong, we will display this message.
$errorMessage = '<strong>There was an error while submitting the form. 
Please try again later</strong>';

/*
*  LET'S DO THE SENDING
*/
// if you are not debugging and don't need error reporting, turn this off 
by error_reporting(0);
error_reporting(E_ALL & ~E_NOTICE);

try
{

if(count($_POST) == 0) throw new \Exception('Form is empty');

$emailTextHtml = "<h1>Felleng Tours Contact Form!</h1><hr>";
$emailTextHtml .= "<table>";

foreach ($_POST as $key => $value) {
    // If the field exists in the $fields array, include it in the email
    if (isset($fields[$key])) {
        $emailTextHtml .= "<tr><th>$fields[$key]</th><td>$value</td> 
</tr>";
    }
}
/*    $emailTextHtml .= "</table><hr>";
$emailTextHtml .= "<p>Have a nice day,<br>Kind Regards,<br>Felleng 
Tours</p>";*/

$mail = new PHPMailer(true);

$mail->setFrom($fromEmail, $fromName);
$mail->addAddress($sendToEmail, $sendToName); // you can add more 
addresses by simply adding another line with $mail->addAddress();
$mail->addAddress($oldEmail, $sendToName); // you can add more addresses 
by simply adding another line with $mail->addAddress();
/*$mail->addAddress($fromEmail, $fromName);*/ // you can add more 
addresses by simply adding another line with $mail->addAddress();
/*    $mail->addReplyTo($_POST['email']);*/

$mail->isHTML(true);

$mail->Subject = $subject;
$mail->msgHTML($emailTextHtml); // this will also create a plain-text 
version of the HTML email, very handy


if(!$mail->send()) {
    throw new \Exception('I could not send the email.' . $mail- 
>ErrorInfo);
}

$responseArray = array('type' => 'success', 'message' => $okMessage);
}
catch (\Exception $e)
{
// $responseArray = array('type' => 'danger', 'message' => $errorMessage);
$responseArray = array('type' => 'danger', 'message' => $e->getMessage());
}


// if requested by AJAX request return JSON response
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && 
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$encoded = json_encode($responseArray);

header('Content-Type: text/plain; charset=utf-8');

echo $encoded;
}
// else just display the message
else {
echo $responseArray['message'];
}
?>
...