今天我尝试制作一个PHP“HTML”编辑器,你可以编写你的“HTML”代码,预览它,然后将它发送到我的电子邮件。以下是代码:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
if (isset($_POST['submit'])){
// $to = file_get_contents('to.txt');
$to = "jonas.geiler@gmail.com";
$subject = "Form to email message";
$message = $_POST["message"];
$header = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$header .= 'From: Skayos Blog <blog.skayo@mail.com>' . "\r\n";
mail($to,$subject,$message,$header);
} else if (isset($_POST['preview'])){
$output = $_POST["message"];
echo $output;
}
?>
<!DOCTYPE html>
<head>
<title>Form submission</title>
</head>
<body>
<form action="" method="post">
Message:<br>
<textarea rows="5" name="message" cols="30"><html> <body> </body> </html></textarea><br>
<input type="submit" name="preview" value="Preview">
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
我的问题:如果我按预览,网页就会重新加载并显示预览,而代码会被删除。有没有简单的方法让代码留在文本框中呢?
谢谢, Skayo