2013-02-22 91 views
1

我一直在爲此奮鬥超過24小時,包括現在。我已經設置我的服務器來設置用戶帳戶,並通過電子郵件向他們發送驗證鏈接。一切運作良好,但我有兩個字符串變量哈希和令牌與從mySql數據庫派生的值的問題。電子郵件生成這些變量分析他們的數據與前三個字符每次錯位了:PHP mangles驗證開始鏈接參數

http://verify.myserver.com/objects/1.8.12.7.10.1.9/verify-email.php?mm_function=submit&hashü41faa912dd9451a8d397fc9386ca1c69&mm_tokenü2rnjrcbhn3qegtu46np03p5pg6aczbtrs51782fkuwq2c8w9m80enutwruydwewca&mm_timezone=2&mm_charset=utf-8 

鏈接應該是:

http://verify.myserver.com/objects/1.8.12.7.10.1.9/verify-email.php?mm_function=submit&hash=fc41faa912dd9451a8d397fc9386ca1c69&mm_token=fc22rnjrcbhn3qegtu46np03p5pg6aczbtrs51782fkuwq2c8w9m80enutwruydwewca&mm_timezone=2&mm_charset=utf-8 

我試圖混合和代碼匹配無濟於事。目前,我的代碼如下:

$weblink = "http://verify.myserver.com/objects/1.8.12.7.10.1.9/verify-email.php?"; 
$weblink . "mm_function=submit&hash=" . $hash . "&mm_token=" . $token . "&mm_timezone=" . $timezone . "&mm_charset=utf-8"; 

有什麼奇怪的是,如果我只是放在$哈希值和$標記的電子郵件作爲一部分,獨立的環節,他們都出來罰款。

我正在使用運行InnoDB引擎的mySql,DB歸類爲latin7_general_ci。

謝謝。

+2

我的猜測是,您的問題來自不同編碼數據庫(拉丁)和電子郵件(UTF -8)。 – oktopus 2013-02-22 14:08:40

+0

我以前一直使用latin7_general_ci,完全沒有任何問題。這是我第一次做一個發送驗證鏈接的應用程序。但爲什麼變量發出正確的字符串,如果不與$ weblink字符串關聯?我會嘗試其他排序規則或其他數據庫引擎。 – DataPriest 2013-02-22 18:46:03

回答

0

事實證明,電子郵件編碼是罪魁禍首。由於Oktopus酒店,我使用的charset = ISO-8859-1像這樣固定它的頭:

if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n"); 

$headers = "From: Some Sender <[email protected]>". PHP_EOL; 
$headers.= "Return-Path: Some Sender <[email protected]>". PHP_EOL; 
$headers.= "Organization: My Organization>". PHP_EOL; 
$headers.= "Content-type: text/plain; charset=iso-8859-1". PHP_EOL; 
$headers.= "MIME-Version: 1.0". PHP_EOL; 
$headers.= "X-Priority: 3". PHP_EOL; 

$weblink = "http://verify.myserver.com/objects/1.8.12.7.10.1.9/process.php?mm_function=submit&"; 
$weblink.= "mm_hash=$hash&mm_token=$verification&mm_timezone=$timezone&mm_charset=iso-8859-1"; 

mail($recipient, "Account Verification Link", "Hello $recipient,". PHP_EOL . PHP_EOL ."Please follow the link below to verify and activate your account:". PHP_EOL . PHP_EOL . $weblink . PHP_EOL . PHP_EOL . "Thank you.". PHP_EOL . PHP_EOL . "App Support Team", $headers); 
+1

我會建議使用'http_build_query()'來構造查詢字符串。 – 2013-02-23 10:26:04

+0

謝謝傑克。作爲一名新手,我總是很高興從社區中學習新事物。 – DataPriest 2013-02-24 18:52:17