我对我制作的表格有疑问。
这是一个很大的形式,我想要的是我收到了数据库中的所有输入(到目前为止我已完成此操作),并且我收到一封电子邮件,其中包含我表单中的所有结果。最终我想要的是一个整洁的程式化电子邮件,提供完整的问题和客户填写的答案。
简而言之:我希望我的表格中的所有问题和答案都放在一封电子邮件中。
<div class="formulier">
<form method="post" enctype="multipart/form-data" action="action.php">
<div id="alginfo">
<div class="col-md-12 red">
<div class="container">
<h3 class="numbers">1</h3>
<h3 class="title">Algemene informatie</h3>
</div>
</div>
<div class="container">
<div class="col-md-6">
<div class="tekstenveld">
<input type="text" class="bigv bedrijfsnaam" name="bedrijfsnaam" required>
<p>Bedrijfsnaam</p>
</div>
<div class="tekstenveld">
<input type="text" class="bigv volledigenaam" name="volledigenaam" required>
<p>Volledige naam</p>
</div>
</div>
<div class="col-md-6">
<div class="tekstenveld">
<input type="text" class="bigv telefoonnummer" name="telefoonnummer" required>
<p>Telefoonnummer</p>
</div>
<div class="tekstenveld">
<input type="text" class="bigv email" name="email" required>
<p>E-mail</p>
</div>
</div>
<div class="col-md-6">
<div class="multikeuze">
<h4>Betreft het een:</h4>
<ul>
<li><span class="error"></span>
<input class="multikeuzes" type="checkbox" name="website" id="website" value="website">
<label for="website" name="website">Website</label></li>
<li><input type="checkbox" name="webshop" id="webshop" value="webshop">
<label for="website" name="webshop">Webshop</label></li>
<li><input type="checkbox" name="app" id="app" value="app">
<label for="website" name="app">App</label></li>
<li><input type="checkbox" name="onlinemarketing" id="onlinemarketing" value="onlinemarketing">
<label for="website" name="onlinemarketing">Online marketing</label></li>
</ul>
<p>Anders</p>
<input type="text" class="bigv anders" name="alginfoanders">
</div>
</div>
</div>
</div>
</div>
<div class="col-md-12 text-center" id="finish">
<input type="submit" name="submit" value="submit">
</div>
</form>
这就是我的HTML,它只是表单的一小部分,因为包含所有内容会使它变得不必要的大。 现在这里来了我的action.php它也缩短了,所以我希望你仍然可以理解发生了什么。
<?php
$servername = "youdliketoknowthat.com";
$username = "butitssecret";
$password = "hunter123";
$dbname = "yougettheidea";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if(isset($_POST['submit'])){
$to = 'me@myemail.com';
$subject = 'Content formulier';
$headers = "From: me@myemail.com\r\n";
$message = 'Bedrijfsnaam: ' . $bedrijfsnaam;
$message .= 'Volledige naam: ' . $volledigenaam;
$message .= 'Telefoonnummer: ' . $telefoonnummer;
$message .= 'email: ' . $email;
mail($to, $subject, $message, $headers);
$bedrijfsnaam = $_POST['bedrijfsnaam'];
$volledigenaam = $_POST['volledigenaam'];
$telefoonnummer = $_POST['telefoonnummer'];
$email = $_POST['email'];
if($volledigenaam !=''||$email !='');
$website = $_POST['website'];
$webshop = $_POST['webshop'];
$app = $_POST['app'];
$onlinemarketing = $_POST['onlinemarketing'];
{
$sql = "INSERT INTO intake_formulier_test (bedrijfsnaam, volledigenaam, telefoonnummer, email, website, webshop, app, onlinemarketing)
VALUES ('$bedrijfsnaam', '$volledigenaam', '$telefoonnummer', '$email', '$website', '$webshop', '$app', '$onlinemarketing')";
}
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
$conn->close();
?>
我希望我明确表达了我想要完成的事情。 我觉得这应该很容易,但我无法在Google上找到适用于我想要做的事情的答案。
答案 0 :(得分:1)
简而言之:
不要这样说:
$message = 'Bedrijfsnaam: ' . $bedrijfsnaam;
在此之前:
$bedrijfsnaam = $_POST['bedrijfsnaam'];
用于mail()函数的所有其他变量的相同内容
你的php脚本应该是这样的:
<?php
$servername = "youdliketoknowthat.com";
$username = "butitssecret";
$password = "hunter123";
$dbname = "yougettheidea";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if(isset($_POST['submit'])){
$bedrijfsnaam = $_POST['bedrijfsnaam'];
$volledigenaam = $_POST['volledigenaam'];
$telefoonnummer = $_POST['telefoonnummer'];
$email = $_POST['email'];
if($volledigenaam !=''||$email !='');
$website = $_POST['website'];
$webshop = $_POST['webshop'];
$app = $_POST['app'];
$onlinemarketing = $_POST['onlinemarketing'];
{
$sql = "INSERT INTO intake_formulier_test (bedrijfsnaam, volledigenaam, telefoonnummer, email, website, webshop, app, onlinemarketing)
VALUES ('$bedrijfsnaam', '$volledigenaam', '$telefoonnummer', '$email', '$website', '$webshop', '$app', '$onlinemarketing')";
}
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
// Now we can send email
$to = 'me@myemail.com';
$subject = 'Content formulier';
$headers = "From: me@myemail.com\r\n";
$message = 'Bedrijfsnaam: ' . $bedrijfsnaam;
$message .= 'Volledige naam: ' . $volledigenaam;
$message .= 'Telefoonnummer: ' . $telefoonnummer;
$message .= 'email: ' . $email;
mail($to, $subject, $message, $headers);
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
$conn->close();
?>
您正在向$ message var添加内容,如下所示: $ message ='Bedrijfsnaam:'。 $ bedrijfsnaam; 但就此而言,对于这个特殊的例子,var $ bedrijfsnaam没有被宣布...... 所以你的$ message var是空的! 在我的例子中,我把所有相关的东西都放在数据库查询后的电子邮件信息中,然后你的所有$ var = $ _POST [“var”] ..