表单的html标记:
<form method="post" action="send_form_email.php">
<div class="form-group">
<label>Name: </label>
<input class="form-control" type="text" placeholder="Enter Name" name="name">
</div>
<div class="form-group">
<label>Email: </label>
<input class="form-control" type="text" placeholder="Enter Email" name="email">
</div>
<div class="form-group">
<label>Message: </label>
<textarea class="form-control" placeholder="Enter Message" name="message"></textarea>
</div>
<button type="submit" name="sended" class="btn btn-default">Submit</button>
</form>
php文件如下,包括2个数组,以便在变量之间进行交换:
<?php
if(!isset($_POST['sended'])) {
died("Йуху");
}
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$mastermail="leshaber24@yandex.ru";
$html = file_get_contents("./email-inlined.html");
// Массивы с заменой
$search = array("#name#", "#email#", "#message#");
$replace = array($name, $email, $message);
$email_message = str_replace($search, $replace, $html);
// create email headers
$headers = 'From: '.$masteremail."\r\n".
'Reply-To:'.$masteremail."\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers .= 'MIME-Version: 1.0'."\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
mail($mastermail, "письмо из Сакуры", $html, $headers);
?>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<h1>Thanks!</h1>
并且邮件本身将进入收件人:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Письмо с сайта</title>
</head>
<body>
<div>
<p>letter comes from <span>#name#</span></p>
<p>email to reply <span>#email#</span></p>
<p>message itself:<br><span>#message#</span></p>
</div>
</body>
</html>
问题是片段不会随来自表单的数据而改变。意味着html数据不会传输到php文件。
谢谢!
答案 0 :(得分:1)
问题在于您传递给邮件功能的内容。在$ html中存储file_contents后,您所做的替换存储在$ email_message中,但您仍然将$ html传递给邮件。
将其更改为
import goslate
big_files = ['lenin.txt', 'liga.txt']
gs = goslate.Goslate()
translation = []
for big_file in big_files:
with open(big_file, 'r') as f:
translated_lines = []
for line in f:
translated_line = gs.translate(line, "en")
translated_lines.append(translated_line)
translation.append('\n'.join(translated_lines))