CSV格式的IP表单数据存储:未定义的错误


Form data store in CSV with IP: Undefined error

我正在尝试从访问者那里获取电子邮件、国家和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";
    }
?> 

表单只有一个字段name="email"和提交按钮

错误不在您的代码中(您粘贴的代码),因为没有提到ip_address