2012-04-03 100 views
0

我試圖設置郵件正文顯示電子郵件中的鏈接,供用戶下載pdf以備日後需要再次下載時使用。它不是html正文,因爲它在大多數顯示html代碼的電子郵件中都不起作用。所以我決定用電子郵件的純文本代替。電子郵件 - 在電子郵件中包裝「a href」鏈接的正確性是什麼?

$umessage .='<a href="'.home_url('/download.php?f=pdffiles/'.$filename).'"><a href="'.home_url('/download.php?f=pdffiles/'.$filename).'">'.$title.'</a>'; 
     }} 

單引號有什麼問題?它顯示在電子郵件:

<a href="http://localhost/download.php?..............">file name</a> 

我不認爲雙引號會有所幫助,對不對?

編輯#2

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n" 

看來,它不會在蘋果以外的任何郵件的電子郵件應用程序很好地工作。

任何想法或者它可能不正確?

編輯#3

$umessage = "Thank you for downloading pdf. \r\n\r\n"; 
     $umessage .= "Please click on the link below to download\r\n"; 
      if(count($selectfiles)>0) 
     { 
      foreach($selectfiles as $key) 
      { 
       $keyArray = explode('@',$key); 

       $filename = $keyArray[1]; 

       $title = $keyArray[0]; 

     $umessage .='<p>Download '. '<a href="'.home_url('/download.php?f=pdffiles/'.$filename).'"><a href="'.home_url('/download.php?f=pdffiles/'.$filename).'">'.$title.'</a></p>'; 

}} 

     $fm ='xxxx'; 
     $to='xxx'; 

     $subject = "Download Request from ". $name; 
     $headers .= 'MIME-Version: 1.0' . "\r\n"; 
     $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
     $headers .= 'From:<'.$fm.'> ' . "\r\n" . 'Reply-To: ' . $to; 

     $uto  = $email; 
     $usubject = "Thank you for Downloading our PDF"; 

     wp_mail($to, $subject, $message, $headers); 
     wp_mail($uto, $usubject, $umessage, $headers); 
+0

我不認爲你可以在純文本文件中放置一個html鏈接。有些電子郵件讀者可能會將其轉換爲。 – Iznogood 2012-04-03 02:50:09

+0

大多數用戶現在使用支持HTML的電子郵件客戶端,我會說90%+ – 2012-04-03 03:47:47

+0

向我們顯示完整的電子郵件代碼。 – 2012-04-03 04:33:58

回答

2

如果你發送的電子郵件爲純文本,那麼你發送任何HTML格式將顯示爲純文本。這與從您的電子郵件中刪除html格式一樣簡單

$umessage .= 'download link: '.home_url('/download.php?f=pdffiles/'.$filename); 
+0

謝謝。我可以問問題嗎?爲什麼HTML格式不能在不同的電子郵件正文中被識別,如Gmail或Outlook?它會顯示html代碼:

示例
joe 2012-04-03 02:53:42

+0

如果您未指定電子郵件的內容類型爲html,則內容將顯示爲純文本,即html將顯示爲文本。如果您發送的郵件含有html,則需要確保頭文件「Content-type:text/html;」與html正文一起正確發送。 – 2012-04-03 02:58:01

+1

我有$ headers。='Content-type:text/html; charset = iso-8859-1'。爲 「\ r \ n」 個;仍然無法正確讀取html – joe 2012-04-03 03:06:41

0

相關鏈接僅適用於網頁環境。在電子郵件中,「/download.php?yadda」的鏈接是沒有意義的,因爲沒有主機可以附加它。

您可以通過使用電子郵件中的鏈接中的完整URL解決這個問題:

$umessage .='<a href="'.home_url('http://example.com/download.php?... 

您還可能能夠應對這種使用<base> tag in your HTML,但可能不被所有的電子郵件客戶端正確解釋。你需要測試。

相關問題