練習用に簡単なお問い合わせフォームを作りましたが、なぜかうまくいきません。これが私のコードです:
<?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 = 'example@example.com';
$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
}
結果はおっと!しかし、なぜそれが機能しないのかわかりません:(事前に感謝します!!