2014-09-30 174 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