0
我正在使用PHP聯繫表單從網站發送電子郵件。我在'index.html'頁面中有表單標記,並使用'process.php'頁面來處理腳本。以PHP電子郵件的形式發送正確的信息
下面是我使用的process.php頁面的代碼:
<?php
require_once('recaptchalib.php');
$privatekey = "my key";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
} else {
header('Location: http://www.mydomain.com/thankyou.html');
}
function sendemail($data)
{
$data["FromIpAddress"] = $_SERVER['REMOTE_ADDR'];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// $headers .= 'To: [email protected]' . "\r\n";
$headers .= 'From: Website - No Reply <[email protected]>' . "\r\n"
$to = '[email protected]';
$info = array();
foreach($data as $key => $value):
if(strpos($key, 'cf-') === false):
$regex = '/(?<!^)((?<![[:upper:]])[[:upper:]]|[[:upper:]](?![[:upper:]]))/';
$string = preg_replace($regex, ' $1', $key);
$info[] = sprintf(' %s: %s, ', $string, $value);
endif;
endforeach;
mail($to, 'New Lead from mydomain.com contact form', implode(" ", $info), $emailbody, $headers);
}
if(isset($_POST['cf-smartsc']) && $_POST['cf-smartsc'] == 'cf'):
sendemail($_POST);
header('Location: http://www.mydomain.com/thank-you.html');
endif;
function sanitize($data){
$data= htmlentities(strip_tags(trim($data)));
$info = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments including CDATA
);
$data = preg_replace($info, '', $data);
return $data;
}
?>
我的問題:我收到的形式的結果,但他們不是很清晰。如果我放置
標記,它們會形成顯示html標記標記的結果。此外,我正在收到reCaptcha答案以及公鑰/私鑰。
有人能幫我製作清晰的郵件回覆嗎?
什麼手段 - 「結果不是很清晰」? – voodoo417
對不起,更具體。從此表單收到的電子郵件顯示混亂的結果,沒有換行符和格式不規則。 – joshSpiderb