我試圖做一個在線代碼編輯器,當你做完我想給用戶一個選項,將所有的代碼發送到他自己的電子郵件中,但每當我嘗試網站不發送代碼<textarea></textarea>
標籤。這是我的代碼。告訴我你是否需要JavaScript和CSS。爲什麼我的郵件不發送textarea?
<!DOCTYPE HTML>
<HTML lang = "en">
<head>
<meta charset = "UTF-8">
<meta name = "author" content = "Adam S. Oates">
<meta name = "description" content = "This HTML file was created to test new thigns I learn">
<meta name = "title" content = "Online Code Editor">
<title title = "Online Code Editor">
Online Code Editor
</title>
<link rel = "apple-touch-icon" href = "">
<link rel = "shortcut icon" href = "">
<link rel = "stylesheet" type = "text/css" href = "main.css">
<script type = "text/javascript" src = "main.js"></script>
</head>
<body>
<header>
Gigaboy <span id = "code"></span> Editor
</header>
<form action = "<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method = "post">
<textarea autocomplete = "off" placeholder = "Type HTML Here" id = "HTMLeditor" name = "HTMLeditor"></textarea>
<a id="CSS"></a>
<textarea autocomplete = "off" placeholder = "Type CSS Here" id = "CSSeditor" name = "CSSeditor"></textarea>
<a id="JavaScript"></a>
<textarea autocomplete = "off" placeholder = "Type JavaScript Here" id = "JSeditor" name = "JSeditor"></textarea>
<span id = "see-result">View Result</span>
<select id = "jqueryMode">
<option value = "OFF">Disable JQuery</option>
<option value = "ON">Enable JQuery</option>
</select>
<select id = "bootstrapMode">
<option value = "OFF">Disable Bootstrap</option>
<option value = "ON">Enable Bootstrap</option>
</select>
<select id = "gigaboyMode">
<option value = "OFF">Disable GigaboyStyle.js</option>
<option value = "ON">Enable GigaboyStyle.js</option>
</select>
<span id = "emailCode">
<input type = "email" name = "email" placeholder = "Send Code to You Email">
<input type = "submit" value = "Send">
</span>
</form>
</body>
</html>
<?PHP
if (!empty($_POST)) {
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type:text/html;charset=UTF-8\r\n";
$msg = str_replace("\n", "<br>", str_replace("\r\n", "<br>", $_POST['HTMLeditor']));
$msg = str_replace("\n", "<br>", str_replace("\r\n", "<br>", $_POST['CSSeditor']));
$msg = str_replace("\n", "<br>", str_replace("\r\n", "<br>", $_POST['JSeditor']));
$HTML = htmlspecialchars($_POST['HTMLeditor']);
$CSS = htmlspecialchars($_POST['CSSeditor']);
$JS = htmlspecialchars($_POST['JSeditor']);
$email = $_POST['email'];
$subject = "Code Made at Gigaboy Code Editor Online";
$message = "HTML5 Code: <br><br>" . $HTML . "<br><br><br>CSS Code: <br><br>" . $CSS . "<br><br><br>JavaScript Code: <br><br>" . $JS;
mail($email, $subject, $message, $headers);
}
?>
您正在混合使用Javascript - 客戶端代碼和PHP - 服務器端代碼。他們只通過AJAX「溝通」。 – Derek
PHP代碼在服務器上生成頁面時運行,在任何html到達客戶端之前爲止。因此該表單尚未呈現給用戶,並且他們無法填寫該表單,因爲直到php完成後它纔會到達它們。 –
我在你的問題中測試了你新編輯的代碼;它沒有任何問題。你還有其他一些'