Reputation: 43
html markup for the form:
<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 file is as follows including 2 arrays to make the swop between variables:
<?php
if(!isset($_POST['sended'])) {
died("Йуху");
}
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$mastermail="[email protected]";
$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>
and the mail itself to be proceeded to the recepient:
<!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>
the problem is that snippets are not changed with the data that comes from the form. Means that html data is not transmitted to php file.
Thanks!
Upvotes: 1
Views: 70
Reputation: 1140
The problem lies with what you are passing to the mail function. After storing the file_contents in $html, the replace you did is stored in $email_message but you still pass $html to the mail.
Change it to
mail($mastermail, "письмо из Сакуры", $email_message, $headers);
Upvotes: 1