2013-08-25 34 views
0

我製作了一個表格,用於在我的網站上與我聯繫。 這是PHP代碼:希伯來語 - 奇怪符號的聯繫表格

<?php 
$errors = ''; 
$myemail = '[email protected]';//<-----Put Your email address here. 
if(empty($_POST['name']) || 
    empty($_POST['email']) || 
    empty($_POST['message'])) 
{ 
    $errors .= "\n Error: all fields are required"; 
} 

$name = $_POST['name']; 
$email_address = $_POST['email']; 
$message = $_POST['message']; 

if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", 
$email_address)) 
{ 
    $errors .= "\n Error: Invalid email address"; 
} 

if(empty($errors)) 
{ 
    $to = $myemail; 
    $email_subject = "Contact form submission: $name"; 
    $email_body = "You have received a new message. ". 
    "name: $name \n\n email: $email_address \n\n\n $message"; 

    $headers = "From: $myemail\n"; 
    $headers .= "Reply-To: $email_address"; 

    mail($to,$email_subject,$email_body,$headers); 
    //redirect to the 'thank you' page 
    header('Location: contact_thanks.html'); 
} 
?> 

當我使用網站上的表格,我收到一個郵件怪異的符號。那是因爲我用希伯來文寫成了英文字母。 當我將「myemail」更改爲另一封郵件時,郵件即使以希伯來語發送也很好,但我希望郵件能夠傳遞給第一封郵件。

我改變了許多次編碼,但似乎沒有解決問題,也許我還沒有嘗試過正確的一個呢。

我不是那個寫代碼的人,我不懂php,所以請給我容易理解的答案。

回答

2

您必須在郵件標題中指定內容編碼。爲此,請添加以下行:

$headers .= "\nContent-type: text/html; charset=UTF-8";