0
我有<meta charset="utf-8" />
一個PHP的形式(我也試圖與<meta charset="ISO-8859-1" />
這給我同樣的結果)PHP接觸形式變化HTML實體編碼成ASCII字符
當我測試的形式與人物"
和'
中,電子郵件,我收到改變這些字符轉換成他們的ASCII字符:
Subject: \"\'
Message: \"\'
Sent by: \"\'
(不知何故,主題字段只增加了一個\
字符前)
我也注意到,在<
和>
之間的任何東西都剝離出來在$formAuthor
和$formContent
但不是在$formSubject
另外,如果從與在驗證碼一個錯誤提交,形式保留在內存中寫着什麼的場,但任何事情之後「中的$formAuthor
和$formSubject
被剝離出來,但不是在$formContent
這不是一個服務器的問題,因爲我只是有這個問題(因爲它沒有遵循比電子郵件問題的一個相同的邏輯很奇怪)用這種形式,而不是與其他人一起。
非常感謝您的幫助!
這裏是PHP形式的某些部分:
// if all the fields have been entered correctly and there are no recaptcha errors build an email message
if (($resp->is_valid) && (!isset($hasError))) {
$emailTo = '[email protected]'; // here you must enter the email address you want the email sent to
$subject = 'Message from: ' . $formAuthor . ' | ' . $formSubject; // This is how the subject of the email will look like
$body = "Email: $formEmail \n\nSubject: $formSubject \n\nMessage: $formContent \n\nSent by: $formAuthor";// This is the body of the email
$headers = 'From: <'.$formEmail.'>' . "\r\n" . 'Reply-To: ' . $formEmail . "\r\n" . 'Return-Path: ' . $formEmail; // Email headers
//send email
mail($emailTo, $subject, $body, $headers);
// set a variable that confirms that an email has been sent
$emailSent = true;
}
$emailSent = true;
}
// if there are errors in captcha fields set an error variable
if (!($resp->is_valid)){
$captchaErrorMsg = true;
}
}
} ?>
這裏是HTML:
<div id="singleParagraphInputs">
<div>
<label for="formAuthor">Name</label>
<input class="requiredField <?php if($authorError) { echo 'formError'; } ?>" type="text" name="formAuthor" id="formAuthor" value="<?php if(isset($_POST['formAuthor'])) echo $_POST['formAuthor'];?>" size="40" />
</div>
<div>
<label for="formEmail">Email</label>
<input class="requiredField <?php if($emailError) { echo 'formError'; } ?>" type="text" name="formEmail" id="formEmail" value="<?php if(isset($_POST['formEmail'])) echo $_POST['formEmail'];?>" size="40" />
</div>
<div>
<label for="formSubject">Subject</label>
<input type="text" name="formSubject" id="formSubject" value="<?php if(isset($_POST['formSubject'])) echo $_POST['formSubject'];?>" size="40" />
</div>
<div id="commentTxt">
<label for="formContent">Message</label>
<textarea class="requiredField <?php if($commentError) { echo 'formError'; } ?>" id="formContent" name="formContent" cols="40" rows="5"><?php if(isset($_POST['formContent'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['formContent']); } else { echo $_POST['formContent']; } } ?></textarea>
</div>
非常感謝您的幫助Mdesdev!我嘗試了你的建議,但這並沒有改變我收到郵件的方式。我也注意到'<' and '>'之間的任何內容都被剝離出$ formAuthor和$ formContent,但不在$ formSubject中。任何想法,如果它是相關的? – JinSnow
@Giom我已經更新了答案,現在就試試。 – mdesdev
感謝您的更新。我確實嘗試了它(也是替代方法),但它並沒有改變我收到我的郵件的方式:在$ formSubject的「and」前面仍然有\,並且它們被改成了$ formAuthor中的ASCII字符並且$ formContent。仍然在< and >之間的任何東西都被剝離出$ formAuthor和$ formContent。我也更新了我的問題中的php代碼,也許它會幫助你更多。再次感謝您的幫助! – JinSnow