2014-09-30 63 views
1

對不起,我知道php很糟糕。表單發送後顯示html內容

我有我的表單發送到我的電子郵件地址的PHP腳本。

<?php 

    class Sendform { 

    private static $from_name = 'Mysite.com'; 
    private static $from_email = '[email protected]'; 
    private static $to_email = '[email protected]'; 


    public function send() { 
     $name = self::getvar('name'); 
     $email = self::getvar('email'); 
     $message = self::getvar('message'); 


     $from_email = self::mime_encode(self::$from_name,"UTF-8")." <".self::$from_email.">"; 


     $subject = 'subject'; 

     $text = "Name: $name 
    E-mail: $email 

    Message: $message"; 


     if($fileName) { 
      $un  = strtoupper(uniqid(time())); 
      $head  = "From: $from_email\n"; 
      $head  .= "To: ".self::$to_email."\n"; 
      $head  .= "Subject: ".self::mime_encode($subject,'UTF-8')."\n"; 
      $head  .= "X-Mailer: PHPMail Tool\n"; 
      $head  .= "Mime-Version: 1.0\n"; 
      $head  .= "Content-Type:multipart/mixed;"; 
      $head  .= "boundary=\"----------".$un."\"\n\n"; 
      $zag  = "------------".$un."\nContent-Type:text/plain; charset=UTF-8\n"; 
      $zag  .= "Content-Transfer-Encoding: 8bit\n\n$text\n\n"; 
      $zag  .= "------------".$un."\n"; 
      $zag  .= "Content-Type: application/octet-stream;"; 
      $zag  .= "name=\"".$fileName."\"\n"; 
      $zag  .= "Content-Transfer-Encoding:base64\n"; 
      $zag  .= "Content-Disposition:attachment;"; 
      $zag  .= "filename=\"".$fileName."\"\n\n"; 
      $zag  .= chunk_split(base64_encode(file_get_contents($tmpName)))."\n"; 

      mail(self::$to_email, self::mime_encode($subject,'UTF-8'), $zag, $head); 
     } else { 
      $from_email = self::mime_encode(self::$from_name,"UTF-8")." <".self::$from_email.">"; 
      $head="From: ".self::$from_email."\r\n"; 
      $head.="X-Mailer: Sertse Mailer\r\n"; 
      $head.="Content-Type: text/plain; charset=UTF-8\r\n"; 
      $head.="Content-Transfer-Encoding: 8bit\r\n"; 
      $head.="X-Priority: 3\r\n"; 

      mail(self::$to_email, self::mime_encode($subject,'UTF-8'), $text, $head); 
      echo "asdasdasdasdasd"; 
     } 

    } 


    private static function mime_encode($text,$charset) { 
     return "=?".$charset."?B?".base64_encode($text)."?="; 
    } 


    private static function getvar($name) { 
     return addslashes(htmlspecialchars(strip_tags($_POST[$name]))); 
    } 

    } 


    $reg = new Sendform; 
    if(isset($_POST['name'])) $reg->send(); 

    ?> 

我想在表單發送後顯示圖像文件,並在2秒後重定向到索引頁。 如果您有幫助添加此功能,我將不勝感激。謝謝!

+1

echo img src and meta refresh?我敢肯定,你可以把這兩個放在一起。 – 2014-09-30 17:16:33

+0

@ fred-ii-請告訴我需要補充的地方。我試圖把它放在'echo「asdasdasd」'中,但是我收到頁面時出現錯誤'Parse error:syntax error,unexpected T_STRING,expect','or';' ' – CroaToa 2014-09-30 17:20:32

+0

'echo'';''''或'echo「」;' – 2014-09-30 17:23:57

回答

5

這裏,試試這個:

mail(self::$to_email, self::mime_encode($subject,'UTF-8'), $text, $head); 
    echo "<img src=\"http://www.example.com/image.jpg\">"; 
    echo '<meta http-equiv="refresh" content="2;url=index.html" />'; 

echo '<META http-equiv="refresh" content="5; URL=index.html">'; 

您可能希望增加2取決於你的圖像文件有多大。

它可能需要額外的時間加載,否則頁面將刷新到設置的位置,而不會完全看到圖像。

如果人們想要直接轉到index.html文件,其他選項可能是在圖像下方回顯您網站的鏈接。

mail(self::$to_email, self::mime_encode($subject,'UTF-8'), $text, $head); 
    echo "<img src=\"http://www.example.com/image.jpg\">"; 
    echo "<br>"; 
    echo "<a href=\"index.html\">Click here to go to the home page</a>"; 
    echo '<meta http-equiv="refresh" content="2;url=index.html" />'; 
+1

謝謝弗雷德!感謝你我學到了這個 – CroaToa 2014-09-30 17:53:34

+0

@CroaToa你非常歡迎:) – 2014-09-30 17:59:29