1
我做了一個簡單的聯繫表單,只是爲了練習,但由於某種原因它不起作用。這裏是我的代碼:我的聯繫表單有什麼問題?
<?php
if($_SERVER['REQUEST_METHOD'] == "POST") {
$required = array('name', 'email', 'onderwerp', 'bericht');
$error = false;
foreach($required as $field) {
if (empty($_POST[$field])) {
$error = true;
}
}
if ($error) {
echo "All fields are required!";
} else {
$to = '[email protected]';
$datum = date("d-m-Y H:i");
$ip = $_SERVER['REMOTE_ADDR'];
$naam = $_POST['name'];
$email = $_POST['email'];
$from = $_POST['email'];
$onderwerp = $_POST['onderwerp'];
$bericht = $_POST['bericht'];
$subject = "New e-mail!: $onderwerp";
$message .= $bericht . "\n\n";
$message .= "-----------------------------\n";
$message .= "From:: " . $name . " (" . $_POST['email'] . ")\n";
$message .= "IP-adres: " . $ip . "\n";
$message .= "Sent on $datum \n";
$headers = 'From: '.$_POST['email'];
$sent_email = mail($to, $subject, $message, $headers);
if (!$sent_email) {
echo "Mail has been sent!";
}
else
{
echo "Woops!";
}
}
}
else {
// Form has not been submitted
}
所以結果是Woops!但我想不出爲什麼事先不工作:( 謝謝!
不敢相信我太傻了......非常感謝! – FrK