2013-01-12 63 views
0

我有一個PHP腳本:) 基本上用戶註冊收到一封電子郵件,然後單擊激活鏈接。當他們點擊激活鏈接時,它會將它們帶到activate.php頁面,並且全部完成。 的問題在他們收到的電子郵件中的鏈接看起來像PHP確認電子郵件鏈接是帶我到錯誤的頁面

Hello用戶名,現在這裏是您的登錄信息:

用戶名:計算
密碼:計算

下一個步驟是點擊此鏈接激活你的賬號:點擊這裏

你可以在上面的最後一行看到,網站的名字加入到了activate.php頁面,鏈接應該帶給他們。所以即時猜測我的錯誤並不是那麼糟糕,我只是缺少正斜槓或類似的東西。 無論如何,我認爲問題來自下面的代碼。我儘可能縮短了代碼。

<? 

// send email 
$myname = $contact_name; 
$myemail = $contact_email; 

$contactname = $signup[fname]; 
$contactemail = $signup[email]; 
$message = "Hello ".$signup[fname].",<BR>". 
"Get ready to start getting the hits you deserve. Now here is your login info:<BR>  <BR>". 
"username: ".$signup[username]."<BR>". 
"password: ".$signup[password]."<BR><BR>". 
"<B>The next step is to click on this link to activate your account:<a href=".$siteUrl."activate.php?username=".$signup[username].">CLICK HERE</a></b>"; 
$subject = $title; 

$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
$headers .= "From: ".$myname." <".$myemail.">\r\n"; 
$headers .= "To: ".$contactemail." <".$contactemail.">\r\n"; 
$headers .= "Reply-To: ".$myname." <".$myemail.">\r\n"; 
$headers .= "X-Priority: 1\r\n"; 
$headers .= "X-MSMail-Priority: High\r\n"; 
$headers .= "X-Mailer: Just My Server"; 

mail($contactemail, $subject, $message, $headers); 
$signup[username] = ""; 
?> 

如果有人可以對此有所瞭解,這將是很好的。以爲我只是提到我使用PHP 5.3 我認爲我自己的問題來自 href =「。$ siteUrl。」activate.php?username =「。$ signup [username]。」> CLICK HERE「; $ subject = $稱號;

但我需要一些一個誰知道一些有效的輸入:)

+0

爲了安全起見,你散列密碼,你也可能要不要發送明文密碼,你可能想添加令牌激活,例如:example.com/activate.php/?token=dhwudf983nsdfwuen&user=nwenwsli2nf82ndj,並檢查用戶和令牌,然後你就會知道這是實際點擊的用戶鏈接 – Class

+0

感謝您的輸入,我將在稍後創建一個獨立的線程。因爲像您說的安全方很跛。所以你可以隨意加入。關心尼日爾。 – user1906671

回答

0

我注意到當你將你的鏈接,您使用$ SITEURL你實際設置變量

。?此外,由於您將從外部來源(電子郵件託管網站)提供服務,因此它可以像您的完整網站地址一樣「硬編碼」您的鏈接。例如:

<a href="http://www.yourwebsite.com/yourdirectories/activate.php?username=".$signup[username].">Click Here</a> 

因此,您的消息值的值可能是。

$message = "Hello ".$signup[fname].",<BR>". 
"Get ready to start getting the hits you deserve. Now here is your login info:<BR>  <BR>". 
"username: ".$signup[username]."<BR>". 
"password: ".$signup[password]."<BR><BR>". 
"<B>The next step is to click on this link to activate your account:<a href='http://www.yourwebsite.comactivate.php?username=".$signup[username]."'>CLICK HERE</a></b>"; 

你不應該有問題與雙斜線,但如果你有一個問題,那你可以使用:

$message = "Hello ".$signup[fname].",<BR>". 
"Get ready to start getting the hits you deserve. Now here is your login info:<BR>  <BR>". 
"username: ".$signup[username]."<BR>". 
"password: ".$signup[password]."<BR><BR>". 
"<B>The next step is to click on this link to activate your account:<a href='http:/"."/www.yourwebsite.com/activate.php?username=".$signup[username]."'>CLICK HERE</a></b>"; 
+0

嗨德文,我剛剛嘗試了你所說的,但當我嘗試實現這個時,我遇到的問題是網址從何處開始IE http://只要我做了2個斜線,我的代碼就會被註釋掉。是否有可能使用我的代碼以上,並實現讓我們說最後幾行,所以我可以做一個複製和粘貼。乾杯尼日爾 – user1906671

+0

謝謝德文,它在早上2.40。我遭到了破壞,並拒絕在這個問題得到解決之前上牀睡覺。你修好了。謝謝尼日爾 – user1906671

+0

@ user1906671:謝謝,我很樂意提供幫助,請記住將我的答案作爲解決方案進行檢查,以便其他人知道答案。 –

2

你需要之間的「一」和「HREF」的空間你的信息。

此外,所有現代電子郵件客戶端都會自動將URL轉換爲鏈接,因此根本沒有必要使用href標籤。

+0

嗨克里斯,這是我在這裏粘貼代碼時不好。 「a」和「href」之間有一段距離,因爲我已經糾正了這個問題,以供其他人看到。謝謝尼日。 – user1906671

0

因爲它是字符串「裏面你需要進行轉義或使用單引號

這裏有一個固定的版本:

$message = "Hello ".$signup[fname].",<br>". 
    "Get ready to start getting the hits you deserve. Now here is your login info:<br>  <br>". 
    "username: ".$signup[username]."<br>". 
    "password: ".$signup[password]."<br><br>". 
    "<b>The next step is to click on this link to activate your account: 
    <a href='".$siteUrl."activate.php?username=".$signup[username].'>CLICK HERE</a></b>"; 
+0

菲利普懷特豪斯,感謝您的答覆我試過你的代碼,我得到這個錯誤。第157行中的D:\ hosting \ 7560507 \ html \ fast \ traffic1 \ reg.php中的解析錯誤:語法錯誤,意外的T_ENCAPSED_AND_WHITESPACE行157是您提供的最後一行代碼。 – user1906671