表单发送后显示html内容

时间:2014-09-30 17:14:17

标签: php html

对不起,我知道php太糟糕了。

我有php脚本将我的表单发送到我的电子邮件地址。

<?php

    class Sendform {

    private static $from_name = 'Mysite.com';
    private static $from_email = 'mailer@Mysite.com';
    private static $to_email = 'myemail@email.com';


    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 个答案:

答案 0 :(得分: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" />';