對不起,我知道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秒後重定向到索引頁。 如果您有幫助添加此功能,我將不勝感激。謝謝!
echo img src and meta refresh?我敢肯定,你可以把這兩個放在一起。 – 2014-09-30 17:16:33
@ fred-ii-請告訴我需要補充的地方。我試圖把它放在'echo「asdasdasd」'中,但是我收到頁面時出現錯誤'Parse error:syntax error,unexpected T_STRING,expect','or';' ' – CroaToa 2014-09-30 17:20:32
'echo'';''''或'echo「」;' – 2014-09-30 17:23:57