2016-12-04 77 views
0

我有下面這個代碼是完美的工作。它將數據發送給數據庫,並同時發送一封包含數據的電子郵件,但我無法弄清楚如何將圖像作爲附件。他們上傳的數據庫中有一張圖片。使用php顯示文本和html

$query = "INSERT INTO postoffers(postedby,reqName,reqEmail,reqHotel,reqOutlet,reqCnum,reqPostType,reqPostHead,reqPostDet,offerStarts,offerEnds,file,type,size) VALUES('$cuser','$rname','$remail','$rhotel','$routlet','$rcnum','$rposttype','$rposthead','$rpostdet','$rbdate','$redate','$file','$file_type','$file_size')"; 

     $res = mysql_query($query); 

     if ($res) { 
      $errTyp = "success"; 
      $errMSG = "Successfully Posted!"; 

      $to = $remail; 
      $subject = "Your Post Offer"; 
      $message = "Hello <strong>" . $cuser . "</strong>,"; 
      $message .= "<table width='600' border='0' cellspacing='10' cellpadding='0'> 
         <tbody> 
         <tr> 
          <td>This is a confirmation that you have posted a new offer for The Concierge App. Please kindly see the details below.</td> 
         </tr> 
         <tr><td> 
         <table width='600' border='1' cellspacing='0' cellpadding='10' bordercolorlight='#B4B1B1'> 
         <tbody> 
          <tr> 
           <td width='166'><strong>Requester Name :</strong></td> 
           <td width='374'>" . $rname . "</td> 
          </tr> 
          <tr> 
           <td width='166'><strong>Email :</strong></td> 
           <td width='374'>" . $remail . "</td> 
          </tr> 
           <td width='166'><strong>Hotel :</strong></td> 
           <td width='374'>" . $rhotel . "</td> 
          <tr> 
           <td width='166'><strong>Outlet Name/Spa Name :</strong></td> 
           <td width='374'>" . $routlet . "</td> 
          </tr> 
          <tr> 
           <td width='166'><strong>Contact Number :</strong></td> 
           <td width='374'>" . $rcnum . "</td> 
          </tr> 
          <tr> 
           <td width='166'><strong>Post Type :</strong></td> 
           <td width='374'>" . $rposttype . "</td> 
          </tr> 
          <tr> 
           <td width='166'><strong>Post Headline :</strong></td> 
           <td width='374'>" . $rposthead . "</td> 
          </tr> 
          <tr> 
           <td width='166'><strong>Post Details :</strong></td> 
           <td width='374'>" . $rpostdet . "</td> 
          </tr> 
          <tr> 
           <td width='166'><strong>Post Begin Date :</strong></td> 
           <td width='374'>" . $rbdate . "</td> 
          </tr> 
          <tr> 
           <td width='166'><strong>Post End Date :</strong></td> 
           <td width='374'>" . $redate . "</td> 
          </tr> 
          <tr> 
           <td width='166'><strong>Display Image :</strong></td> 
           <td width='374'>" . $file . "</td> 
          </tr> 
         </tbody> 
         </table> 
         </td></tr> 
         </tbody> 
         </table>"; 

      $headers = 'From: [email protected]' . "\r\n" . 
      $headers = "MIME-Version: 1.0" . "\r\n" . 
      $headers = "Content-type:text/html;charset=iso-8859-1" . "\r\n" . 
         'Reply-To: [email protected]' . "\r\n" . 
         'X-Mailer: PHP/' . phpversion(); 

      mail($to, $subject, $message, $headers); 

最糟糕的部分原因

<tr> 
    <td width='166'><strong>Display Image :</strong></td> 
    <td width='374'>" . $file . "</td> 
</tr> 

一段代碼顯示圖像的文件名。

+0

http://stackoverflow.com/questions/12301358/send-attachments-with-php-mail – Banzay

+0

你的標題的網址並且描述似乎在問兩個不同的東西,那麼它是哪一個? –

回答

0

您應該使用正確的標籤來顯示圖像。您的代碼應該是這樣的:

<td><img src='$file'></td> 

$file應該包含您的圖像