Я пытаюсь получить электронную почту, страну и IP-адрес от посетителя и сохранить в CSV, а также отправлю электронное письмо владельцу сайта.
Я не очень знаком, но большинство вещей работает, но не могуизбавиться от неопределенной ошибки для $cvsData .= "\"$email\",\"$ip\"".PHP_EOL;
строки ...
Error Message: Notice: Undefined index: ip_address in
Вот мой код
<?php
// this is to store form into csv file
if(isset($_POST["submit"]))
{
$email = $_POST["email"];
$ip = $_SERVER['REMOTE_ADDR'];
if(empty($email))
{
echo "ERROR MESSAGE";
die;
}
$cvsData .= "\"$email\",\"$ip\"".PHP_EOL;
$fp = fopen("emails.csv", "a");
if($fp)
{
fwrite($fp,$cvsData); // Write information to the file
fclose($fp); // Close the file
echo "<h3>Thank you! we will inform you.....</h3>";
}
}
// this is to send email to site owner
// Contact subject
$email ="$email";
// Enter your email address
$to ='myemail@site.com';
$subject ='site Email Submited';
$send_email=mail($to,$email,$subject);
// Check, if message sent to your email
// display message "We've recived your information"
if($send_email){
echo "Email address is sent to the department.";
} else {
echo "ERROR";
}
?>
Форма имеет только одно имя поля = "email"и отправить кнопку