我的联系表格有问题。当我发送它时,我得到了没有发件人和消息等的空白邮件。我已经多次更改了代码,但它仍然发送空白邮件。这是HTML代码:
<form id="contact-form" class="contact" action="contact.php" method="post">
<input class="contact-input white-input" type="text" required="" name="contact-names" placeholder="Ime in priimek*" required />
<input class="contact-input white-input" type="email" required="" name="contact-email" placeholder="Elektronski naslov*" required />
<font color="white" style="display: table;">Nagradne igre:</font>
<select id="izbira" name="paket" style="display:table;">
<option value="">Izberite paket...</option>
<option value="Osnovnipaket">Osnovni paket (250€ + DDV)</option>
<option value="Standardnipaket">Standardni paket (800€ + DDV)</option>
<option value="Premiumpaket">Premium paket (999€ + DDV)</option>
</select>
<br><font color="white" style="display: table;">Nabiranje oboževalcev</font><br>
<select id="izbirao" name="paketo" style="display:table;">
<option value="">Izberite paket...</option>
<option value="Osnovnipaket">Osnovni paket (250€ + DDV)</option>
<option value="Standardnipaket">Standardni paket (800€ + DDV)</option>
<option value="Premiumpaket">Premium paket (999€ + DDV)</option>
</select>
<textarea class="contact-commnent white-input" rows="2" cols="20" name="contact_message" placeholder="Vaše sporočilo..."></textarea>
<input type="submit" value="Pošlji" name="submit" id="submit-button" class="contact-submit" style="display:block;" />
</form>
这是contact.php代码:
error_reporting(E_ALL);
ini_set('display_errors', '1');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST["contact-email"])) { $email = $_POST["contact-email"]; }
if (isset($_POST["contact-names"])) { $ime = $_POST["contact-names"]; }
if (isset($_POST["paket"])) { $paket = $_POST["paket"]; }
if (isset($_POST["paketo"])) { $paketobozevalci = $_POST["paketo"]; }
if (isset($_POST["contact_message"])) { $test = $_POST["contact_message"]; }
$sporocilo = "Paket nagradna igra: $paket". "Paket oboževalci: $paketobozevalci". "Sporočilo: $test";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: '. $email .'' . "\r\n";
$headers .= 'Reply-To: '.$email ."\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$subject = "Kontaktni obrazec";
$poslji = mail("mariomail22@gmail.com",$subject,$sporocilo,$headers);
if ($poslji)
{
echo '<style>.contact_success_box {display:block;}</style>';
}
}
答案 0 :(得分:1)
$ paket 未在任何地方设置。
您可以在代码的开头设置所有变量。通过这种方式,它们都可以设置为某些内容,并且您可以更轻松地查看代码中使用的变量。
此外,您可以尝试稍微清理一下代码,当代码打包时很难读取代码。
当您收到包含行号的错误消息时,如果每行上没有太多代码,您可以更轻松地找到问题。
并在mail()funktion失败时发出错误消息,而不仅仅是成功消息。
error_reporting(E_ALL);
ini_set('display_errors', '1');
$mailto = "user@example.com";
$email = "";
$ime = "";
$paket = "";
$paketobozevalci = "";
$test = "";
$sporocilo = "";
$headers = "";
$subject = "Kontaktni obrazec";
$poslji = null;
$succes = '<style>.contact_success_box {display:block;}</style>';
$failure = '<style>.contact_failure_box {display:block;}</style>';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST["contact-email"])) {
$email = $_POST["contact-email"];
}
if (isset($_POST["contact-names"])) {
$ime = $_POST["contact-names"];
}
if (isset($_POST["paket"])) {
$paket = $_POST["paket"];
}
if (isset($_POST["paketo"])) {
$paketobozevalci = $_POST["paketo"];
}
if (isset($_POST["contact_message"])) {
$test = $_POST["contact_message"];
}
$sporocilo .= "Paket nagradna igra: $paket";
$sporocilo .= "Paket oboževalci: $paketobozevalci";
$sporocilo .= "Sporočilo: $test";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: ' . $email . "\r\n";
$headers .= 'Reply-To: ' . $email . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$poslji = mail($mailto, $subject, $sporocilo, $headers);
if ($poslji) {
echo $succes;
} else {
echo $failure;
}
}