2013-07-25 16 views
0

我有一個數據庫,並且當查詢與我們的數據庫中的任何內容不匹配時,我試圖將我的電子郵件地址顯示爲超鏈接。我用下面...如何在php結果中顯示超鏈接的電子郵件

PHP代碼...

else{ // if there is no matching rows do following 

    echo "<br /><br /><br /><strong><h2>"."You have searched a term that is not in the database. Please contact <a href=\"mailto:[email protected]" . htmlentities($_POST['[email protected]']) . "\">".htmlentities($_POST['[email protected]']) . "</a>, if you think this term should be added."."</h2></strong>"; 

但是,結果我得到這個樣子...

「您搜索這個術語不在數據庫中,如果你認爲應該加上這個術語,請聯繫。「

除了超鏈接的電子郵件地址,一切都在那裏。

想法?

回答

1

試試這個..

else{ // if there is no matching rows do following 
    $mail = htmlentities('[email protected]'); 
    echo "<br /><br /><br /><strong><h2>" . 
     "You have searched a term that is not in the database. Please contact <a href=\"mailto:$mail\">$mail</a>, if you think this term should be added.</h2></strong>"; 
+0

您的解決方案非常完美。爲什麼要刪除'$ _POST []'? – webfrogs

+0

爲什麼你添加了$ _POST?如果郵件地址不是用表單發送的(這對我來說沒什麼意義..)你不必使用$ _POST – Philipp

+0

好的。我很困惑。謝謝。 3分鐘以標記爲正確。 – webfrogs

0

此:

$_POST['[email protected]'] 

應該改成這樣:

$_POST['email']; 

其中電子郵件是你的表單字段。這隻有在您將前一頁的電子郵件地址作爲表單字段獲得價值時纔有效。如果情況並非如此,那麼只需用「[email protected]」替換$ _POST ['[email protected]'];

+0

完成。結果仍然是空白。我在哪裏添加我的電子郵件的文本? – webfrogs

+0

你可以發佈更多的代碼,尤其是表單嗎? – Maximus2012

+1

這樣做:echo'

'; print_r($_POST); echo '
';確保$ _POST具有您想要的內容 – George

2
<a href="mailto:<?php echo $_POST['email_field_name']; ?>"> 
    <?php echo $_POST['email_field_name']; ?> 
</a> 

儘管您可能想要提供一些電子郵件地址混淆的機制。這將爲垃圾郵件機器人挖掘您的電子郵件地址爲您的用戶提供一定程度的保護。通常不受保護的地址(如上例所示)隨着時間的推移會收到越來越多的垃圾郵件。

如果您顯示它們的頁面在登錄後受到保護,則問題更少。

+0

此網站將位於AD服務器內部。謝謝。 – webfrogs

0

$_POST['[email protected]']應該$_POST['email']mailto之後不應該有[email protected]。您的聲明應該是這樣的:

echo "<br /><br /><br /><strong><h2>"."You have searched a term that is not in the database. Please contact <a href='mailto:" . htmlentities($_POST['email']) . "'>".htmlentities($_POST['email']) . "</a>, if you think this term should be added."."</h2></strong>"; 
相關問題